grep
The Grey Wolf
greywolf at unisoft.UUCP
Wed Nov 7 11:39:26 AEST 1990
In article <24925 at adm.BRL.MIL> rbottin at atl.calstate.edu writes:
>tiefel at sunshine.Kodak.com asked for a way to searach a structure
>for files that have a string. Here are some probable solutions:
>
>The ultimate helper would be a little script called "hunter" perhaps
>: Usage: hunter string directory
>if [ $# -ne 2 ]; then echo Usage: hunter string directory; exit 1; fi
>for d in $2/*
>do
> if [ -d $d ]
> then hunter $1 $d
> elif grep $1 $d >/dev/null
> then echo $d; grep $1 $d # inefficient but avoids tmpfiles
> fi
>done
>: disclaimer - this is a quick hack and needs testing.
Disclaimer noted.
Everyone seems to think that some sort of echo statement is needed for the
filenames. Use
grep $string $file /dev/null
This way, the file containing the matching string is printed before the
match.
A portable way of doing this, though VERY inefficient is:
find . -type f -exec grep $string '{}' /dev/null \;
Shell solutions are trivial and left as an exercise to the imagination.
:-)
>
>Dick Botting CalState San Bernardino
>rbottin at atl.calstate.edu
--
"This is *not* going to work!"
"Well, why didn't you say so before?"
"I *did* say so before!"
...!{ucbvax,acad,uunet,amdahl,pyramid}!unisoft!greywolf
More information about the Comp.unix.questions
mailing list