Shell script which will look for file

Shell script which will look for file

Post by Pawel » Wed, 23 Oct 2002 01:05:17



    Hi.
I dont know what , to do. I must made script which will found in current
directory  files ,
which have in their body their name. I dont know what too do. I must do this
without
sed, ed and awk etc. . Maybe at the begining small sugestion? Regards. Paul.
                            P.S. Sorry for my english
 
 
 

Shell script which will look for file

Post by Stephane Chazela » Wed, 23 Oct 2002 01:14:11



> I dont know what , to do. I must made script which will found in current
> directory  files ,
> which have in their body their name. I dont know what too do. I must do this
> without
> sed, ed and awk etc. . Maybe at the begining small sugestion? Regards. Paul.
>                             P.S. Sorry for my english

for file in *; do
  fgrep -l -- "$file" "$file"
done

or

for file in *; do
  case $(< $file) in
    *"$file"*) printf '%s\n' "$file";;
  esac
done

# (none tested)

--
Stphane

 
 
 

Shell script which will look for file

Post by Bruce Burhan » Wed, 23 Oct 2002 01:27:49




> > I dont know what , to do. I must made script which will found in current
> > directory  files ,
> > which have in their body their name. I dont know what too do. I must do
this
> > without
> > sed, ed and awk etc. . Maybe at the begining small sugestion? Regards.
Paul.
> >                             P.S. Sorry for my english

> for file in *; do
>   fgrep -l -- "$file" "$file"
> done

> or

> for file in *; do
>   case $(< $file) in
>     *"$file"*) printf '%s\n' "$file";;
>   esac
> done

> # (none tested)

> --
> Stphane

A number of people here have jumped all over my
case for posting untested scripts,  going so far
as to send me abusive e-mails.

Now I shall wait and see if they have any integrity
or were just trying to pull some kind of sick power
trip.

I have those e-mails right in front of me.

Bruce<+>

 
 
 

Shell script which will look for file

Post by tri.. » Wed, 23 Oct 2002 01:41:45


Pawel S said:

Quote:>     Hi.
> I dont know what , to do. I must made script which will found in current
> directory  files ,
> which have in their body their name. I dont know what too do. I must do this
> without
> sed, ed and awk etc. . Maybe at the begining small sugestion? Regards. Paul.
>                             P.S. Sorry for my english

i hope you can use grep. then this should work:

for i in *; do
        grep "$i" "$i" 2>/dev/null 1>&2 && echo "$i"
done

but if you don't have even grep, still don't lose your hope :)

for i in *; do
        while read f; do
                [ "${f#*$i*}" == "" -a ! -z "$f" ] && echo "$i"
        done < "$i"
done

greetings...

ps. if you'll have any problems, try my email (in polish)

--

http://tri10o.republika.pl http://www.bsod.org

 
 
 

Shell script which will look for file

Post by Doug Mill » Wed, 23 Oct 2002 02:11:57




[snip]
>> # (none tested)

>> --
>> Stphane

>A number of people here have jumped all over my
>case for posting untested scripts,  going so far
>as to send me abusive e-mails.

Well, not exactly. You've been flamed, and rightly so, for posting untested
scripts that are not identified as untested, and do not work.

Stphane stated that neither of the scripts he posted has been tested.

And both of them work.

Quote:>Now I shall wait and see if they have any integrity
>or were just trying to pull some kind of sick power
>trip.

Not the same situation. Not at all.
Quote:

>I have those e-mails right in front of me.

No kidding?

Quote:>Bruce<+>

Regards,
        Doug Miller
--
Real email address is alphageek /at/ milmac /dot/ com

.. Ted Kennedy's car has killed more people than my gun.

 
 
 

Shell script which will look for file

Post by Pawel » Wed, 23 Oct 2002 02:15:56


    Many thaks for your help, this examples are opening my eyes.
I wish all of you good day. Paul
    P.S. Sory for my english again.
 
 
 

Shell script which will look for file

Post by Chris F.A. Johnso » Wed, 23 Oct 2002 02:25:57




>> I dont know what , to do. I must made script which will found in current
>> directory  files ,
>> which have in their body their name. I dont know what too do. I must do this
>> without
>> sed, ed and awk etc. . Maybe at the begining small sugestion? Regards. Paul.
>>                             P.S. Sorry for my english

> for file in *; do
>   fgrep -l -- "$file" "$file"
> done

    I'd test for, and skip, directories:

       [ -d "$file" ] || fgrep -l -- "$file" "$file"

    or:

       [ -f "$file" ] && fgrep -l -- "$file" "$file"

    Though if you're using GNU grep, the -s option will suffice.

Quote:> or

> for file in *; do
>   case $(< $file) in

    When there is an insignificant difference between portable and
    non-portable syntax, I prefer the more portable:

       [ -f "$file" ] && case `cat "$file"` in

Quote:>     *"$file"*) printf '%s\n' "$file";;
>   esac
> done
> # (none tested)

--
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2002, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License
 
 
 

Shell script which will look for file

Post by tri.. » Wed, 23 Oct 2002 01:58:57


Bruce Burhans said:

Quote:>> for file in *; do
>>   fgrep -l -- "$file" "$file"
>> done

>> or

>> for file in *; do
>>   case $(< $file) in
>>     *"$file"*) printf '%s\n' "$file";;
>>   esac
>> done

(tested, works better than mine)

Quote:> A number of people here have jumped all over my
> case for posting untested scripts,  going so far
> as to send me abusive e-mails.
> Now I shall wait and see if they have any integrity
> or were just trying to pull some kind of sick power
> trip.

you see, some people here don't have to test their script's
because they are very good in scripting, but maybe there were something
wrong with your scripts (maybe they simply didn't worked?)...

Quote:> I have those e-mails right in front of me.

make a website with them ;)

--

http://tri10o.republika.pl http://www.bsod.org

 
 
 

Shell script which will look for file

Post by Stephane CHAZELA » Wed, 23 Oct 2002 04:36:54



[...]

Quote:>> for file in *; do
>>   fgrep -l -- "$file" "$file"
>> done

>     I'd test for, and skip, directories:

>        [ -d "$file" ] || fgrep -l -- "$file" "$file"

You're right. However, strictly speaking, the OP didn't mention
what he wanted to do about directories. On HPUX, for instance

$ mkdir dir
$ touch dir/dir
$ fgrep -l dir dir
dir

because dir contains "dir", i.e. a file (or directory
or whatever) whose name contains "dir". A directory can also be
considered as a file.

But, it's a good point. Non-regular files (fifos, devices,
sockets, doors, symlinks, directories...) should probably be
skipped as they could cause the script to hang or return
unexpected results.

[...]

Quote:>     Though if you're using GNU grep, the -s option will suffice.

Also note those options:
  -d, --directories=ACTION  how to handle directories
                            ACTION is 'read', 'recurse', or 'skip'
  -D, --devices=ACTION      how to handle devices, FIFOs and sockets
                            ACTION is 'read' or 'skip'

--
Stphane

 
 
 

Shell script which will look for file

Post by Bruce Burhan » Wed, 23 Oct 2002 08:38:10



Quote:> In article <9WVs9.6578

[...]

Quote:> >A number of people here have jumped all over my
> >case for posting untested scripts,  going so far
> >as to send me abusive e-mails.

> Well, not exactly. You've been flamed, and rightly so, for posting
untested
> scripts that are not identified as untested, and do not work.

So you have copies of the e-mails I am referring
to?

Please post them for everyone to see.

Bruce<+>

 
 
 

Shell script which will look for file

Post by Doug Mill » Wed, 23 Oct 2002 22:03:01





>> In article <9WVs9.6578
>[...]

>> >A number of people here have jumped all over my
>> >case for posting untested scripts,  going so far
>> >as to send me abusive e-mails.

>> Well, not exactly. You've been flamed, and rightly so, for posting
>untested
>> scripts that are not identified as untested, and do not work.

>So you have copies of the e-mails I am referring
>to?

>Please post them for everyone to see.

No, Bruce, I'm talking about the newsgroup postings. DUH!

Regards,
        Doug Miller
--
Real email address is alphageek /at/ milmac /dot/ com

.. Ted Kennedy's car has killed more people than my gun.

 
 
 

Shell script which will look for file

Post by Bruce Burhan » Thu, 24 Oct 2002 04:28:50







> >> In article <9WVs9.6578
> >[...]

> >> >A number of people here have jumped all over my
> >> >case for posting untested scripts,  going so far
> >> >as to send me abusive e-mails.

> >> Well, not exactly. You've been flamed, and rightly so, for posting
> >untested
> >> scripts that are not identified as untested, and do not work.

> >So you have copies of the e-mails I am referring
> >to?

> >Please post them for everyone to see.

> No, Bruce, I'm talking about the newsgroup postings. DUH!

No,  actually.  What you  are expressing is a
number of neuroses that I am incapable of helping
you with.

May I suggest  a change of medication?

Or, alternatively,  you could just get a life.

Bruce<+>

- Show quoted text -

Quote:

> Regards,
> Doug Miller
> --
> Real email address is alphageek /at/ milmac /dot/ com

> .. Ted Kennedy's car has killed more people than my gun.

 
 
 

Shell script which will look for file

Post by Doug Mill » Thu, 24 Oct 2002 04:52:48









>> >> In article <9WVs9.6578
>> >[...]

>> >> >A number of people here have jumped all over my
>> >> >case for posting untested scripts,  going so far
>> >> >as to send me abusive e-mails.

>> >> Well, not exactly. You've been flamed, and rightly so, for posting
>> >untested
>> >> scripts that are not identified as untested, and do not work.

>> >So you have copies of the e-mails I am referring
>> >to?

>> >Please post them for everyone to see.

>> No, Bruce, I'm talking about the newsgroup postings. DUH!

>No,  actually.  What you  are expressing is a
>number of neuroses that I am incapable of helping
>you with.

>May I suggest  a change of medication?

>Or, alternatively,  you could just get a life.

In future, please wait to post until *after* you sober up.

Regards,
        Doug Miller
--
Real email address is alphageek /at/ milmac /dot/ com

.. Ted Kennedy's car has killed more people than my gun.

 
 
 

1. Copy files using filenames from text files with shell script or bash script

How can I do this????

I have the file "lista.txt", and this file have the next information:
     one.txt
     two.txt
     five.txt
    six.txt
-------------------
This files exist in the same directory that "list.txt", I would like to
copy this files to other directory

Using Windows the batch file would be like this:  for /f "tokens=*" %i
in (list.txt) do copy "%i" destdir\

How can I do something like that in REDHAT??

Best Regards

2. Linux INFO-SHEET

3. Looking for shell script to DOS batch file converter

4. UNIX performance

5. How to attach file to EMAIL MESSAGE within shell script(Korn shell)

6. How to copy files from a device to a PC using serial communication.

7. NEWBIE-Shell scripting - When to use script variable vs. create tmp file???

8. OpenBSD 2.6 Remote reboot problem

9. handling SIGINT in shell scripts when executing another shell script.

10. Q: How can I have a shell script call another shell script...

11. Shell script invoking other shell scripts

12. Convert Bash shell script to Korn shell script

13. Shell Script Help (C-Shell Script)