Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 13 Jul 1996 13:21:51 -0700
From:      bmah@cs.berkeley.edu (Bruce A. Mah)
To:        tcg@ime.net
Cc:        FreeBSD-Questions <questions@freebsd.org>, bmah@cs.berkeley.edu
Subject:   Re: Recursive grep. 
Message-ID:  <199607132021.NAA16168@conviction.CS.Berkeley.EDU>
In-Reply-To: Your message of "Sat, 13 Jul 1996 14:47:11 EDT." <31E7EF2F.4258@ime.net> 

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multipart MIME message.

--===_0_Sat_Jul_13_13:19:49_PDT_1996
Content-Type: text/plain; charset=us-ascii

Gary Chrysler writes:
> Could someone please show me an example using grep to search
> through files in a tree. ie: recursivly.
> 
> I've read the grep man page, No luck, Tried piping various things
> into grep without success!

Gary--

I've used the following script for awhile.  Ugly as sin, but it gets 
the job done (run it at the top of the tree you want to recursive grep 
through).

Hope this helps...

Bruce.





--===_0_Sat_Jul_13_13:19:49_PDT_1996
Content-Type: application/x-script
Content-Description: rgrep

#!/bin/csh -f
# $Id: rgrep,v 1.1 1992/07/04 18:34:15 bmah Exp bmah $
#
# $Header: /db/users/bmah/bin/RCS/rgrep,v 1.1 1992/07/04 18:34:15 bmah Exp bmah $
#
# rgrep
# Bruce A. Mah (bmah@tenet.berkeley.edu)
#
# Recursive grep.
#
# $Log: rgrep,v $
# Revision 1.1  1992/07/04  18:34:15  bmah
# rgrep won't try to grep directories now.
#
# Revision 1.0  1992/07/02  19:10:04  bmah
# Initial revision
#
#
if ($#argv == 2) then
	set noglob
	find . \! -type d -name $2 -exec grep $1 {} /dev/null ";"
	unset noglob
else if ($#argv == 1) then
	set noglob
	find . \! -type d -exec grep $1 {} /dev/null ";"
	unset noglob
else
	echo "usage: rgrep {target}"
	echo "       rgrep {target} {filespec}"
endif

--===_0_Sat_Jul_13_13:19:49_PDT_1996--





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199607132021.NAA16168>