Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!unisoft!greywolf From: greywolf@unisoft.UUCP (The Grey Wolf) Newsgroups: comp.unix.questions Subject: Re: grep Message-ID: <3213@unisoft.UUCP> Date: 7 Nov 90 00:39:26 GMT References: <24925@adm.BRL.MIL> Reply-To: greywolf@unisoft.UUCP (The Grey Wolf) Organization: Foo Bar and Grill Lines: 42 In article <24925@adm.BRL.MIL> rbottin@atl.calstate.edu writes: >tiefel@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@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