Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 14 Nov 2003 08:50:12 +0000 (GMT)
From:      Jan Grant <Jan.Grant@bristol.ac.uk>
To:        Francisco Reyes <lists@natserv.com>
Cc:        FreeBSD Questions List <questions@freebsd.org>
Subject:   Re: Recursion with grep?
Message-ID:  <Pine.GSO.4.58.0311140844210.11603@mail.ilrt.bris.ac.uk>
In-Reply-To: <20031113234031.G85730@zoraida.natserv.net>
References:  <20031113173505.F84157@zoraida.natserv.net> <20031113223611.X85161@zoraida.natserv.net> <200311141504.57201.jrhoden@unimelb.edu.au> <20031113234031.G85730@zoraida.natserv.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 13 Nov 2003, Francisco Reyes wrote:

> On Fri, 14 Nov 2003, JacobRhoden wrote:
>
> > No need to hack grep plese! just use -R (it appears the man page does not
> > document the -R function, but you need to use -R in grep for it to recurse.
>
> -R == -r
>
> That was mentioned in the previous emails. It only recurses directories.
> It will not work with a filemask.
>
> You can't say
> grep -r <string> *.c
>
> You can only say
> grep -r <string> <directory>

That's correct, but the Unix Way is* to use small tools that do one job
well* and compose them for the desired effect. Someone's already given
you an invocation of find and xargs that (almost) does what you want:

find . -type f -name \*.c -print0 | xargs -0 grep -h searchstring

If you like, wrap this up with a script. Call the script "grep" and
stick it closer to the start of your path than the system one.

Even the win32 shell is more capable of command composition these days.
Chucking as much disparate functionality as possible into each tool
is a poor tactic because you wind up with every tool being
indistinguishable from its peers, modulo the totally incompatible and
irregular interface :-)

G'luck,
jan

* allegedly :-)

-- 
jan grant, ILRT, University of Bristol. http://www.ilrt.bris.ac.uk/
Tel +44(0)117 9287088 Fax +44 (0)117 9287112 http://ioctl.org/jan/
and Nostradamus never dreamed of the Church of the Accellerated Worm



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