home *** CD-ROM | disk | FTP | other *** search
Wrap
Newsgroups: comp.unix.shell Path: sparky!uunet!gatech!udel!rochester!rocksanne!news From: randy@ess.mc.xerox.com (Randy Stegbauer) Subject: Re: need a bit of help in Message-ID: <1993Jan5.140031.4710@spectrum.xerox.com> Sender: news@spectrum.xerox.com Reply-To: stegbauer.wbst129@xerox.com Organization: Xerox, Rochester, NY References: <1993Jan4.181902.20122@newscan.canada.sun.com> Date: Tue, 5 Jan 1993 14:00:31 GMT Lines: 44 In article 23031@mnemosyne.cs.du.edu, rduta@nyx.cs.du.edu (Radu) writes: >> >>2) I was wandering what is the easiest way to do a recursive grep, where In article 20122@newscan.canada.sun.com, beric@sunvcr.canada.sun.com (Beric Maass - Sun Vancouver SPS) writes: > >find . -type f -exec grep -i string_to_search /dev/null {} \; This works fine when none of the directories are symbolic links. However 'find' does not follow links. I use the following shell script for recursive greps. (Please excuse the fact that it is a csh script. I wrote it before I was enlightened to sh programming.) --------------------- BEGIN script rgrep --------------------- #!/bin/csh -f if ($#argv < 3) then set _program = $0 echo usage: $_program:t directory pattern_to_find files_to_search... echo use single quotes around 'pattern' and 'files' echo if they contain meta-characters. exit 1 else set _curr_dir = $1; shift set _pattern = "$1"; shift cd $_curr_dir grep "$_pattern" $argv /dev/null |& \ sed -e "/^grep: .*: No /D" \ -e "/^grep: .*: Is a directory/D" \ -e "/^No match./D"\ -e "s@^@$cwd/@" set _next_dirs = ( .[^\.] .??* * ) >& /dev/null if ( $#_next_dirs != 0 ) then foreach file ( $_next_dirs ) if ( -d $file ) $0 $file "$_pattern" "$argv" end endif endif --------------------- END script rgrep --------------------- --- Randy Stegbauer Phone: (716)422-3236 Mail: stegbauer.wbst129@xerox.com