Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!adm!news From: rbottin@atl.calstate.edu Newsgroups: comp.unix.questions Subject: Re: grep Message-ID: <24925@adm.BRL.MIL> Date: 3 Nov 90 02:59:55 GMT Sender: news@adm.BRL.MIL Lines: 34 tiefel@sunshine.Kodak.com asked for a way to searach a structure for files that have a string. Here are some probable solutions: find some_directory -type f -exec grep string '{}' \; -print This is hard work and puts file names after thelines that match. for d in *;do grep string $d/*; done is bourne/Korn shell dependent and may be faster if ONLY one level needs to be searched (and has no directories). ls -Rf|while read f;do grep string $f && echo $f; done is faster than the 'find'....and there is a similar 'awk'ish solution ls...|awk '{system("grep string " $0)}' which fails to indicate which file the line occurs, but is kind of neat otherwise. 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. Dick Botting CalState San Bernardino rbottin@atl.calstate.edu