[Scottish] Best way to find text within files recursively?

David Marsh's list-reading hat scottish at mailman.lug.org.uk
Tue Jan 21 19:35:04 2003


On Sat, 18 Jan 2003 20:48:28 +0000
Graeme Mathieson <mathie+slug@wossname.org.uk> wrote:

> On Sat, Jan 18, 2003 at 07:55:38PM +0000, Allan Whiteford wrote:
> > 
> > In a slightly more convoluted way, but one in which can be applied
> > easily to any command to give recursive capabilities:
> > 
> > grep -l myfriend@somewhere.org `find .`
> > 
> > (Note the direction of the quotes, 

Yes, I keep forgetting about the usefulness of backquoting in output
when you need it..

> > and also filenames with spaces will probably mess things up.)

Filenames with spaces are pure evil, in my opinion.
Should never have been invented, that's what the "-" key is for :)
(But not "_", they're probably even worse)

> It's also going to break grep if find returns too many results. 

Yeah, that's the problem I had with my initial (and probably utterly
wrong) guess of: grep foo */*

 
> kindly to.  My SOP recursive grep is:

SOP?

> find . -type f -print0 |xargs -0 grep 'foo'

OK, not being hot on shellspeak, I'm guessing. Is that:

Find (in cwd downwards) "files" of type 'file',
return/print in some special format (0???),
then pipe that to xargs (a known good friend)
with ..ah, ah-ha: null terminators (xargs manpage references this in
find also) - let me guess, that sorts out sifting files with spaces,
and then grep for the string on that?

Neat! :)




-- 
David Marsh, <email valid @time of writing> | http://web.viewport.co.uk/