[Techtalk] real life kewl text-processing and regexps samples
wanted
Julie
txjulie at austin.rr.com
Sat Jan 10 23:16:54 EST 2004
Daniel wrote:
> On Fri, Jan 09, 2004 at 07:14:51PM -0800, Elena Bevell wrote:
>
>>I like this recursive grep that I found somewhere:
>>
>>find . -type f -exec grep "thing-to-find" {} \;
>
>
> This works, but it is horribly slow.
>
> find . -type f -print0 | xargs -0 grep "thing-to-find"
>
> is a lot faster. The first one forks and execs' on every file it
> finds. The second one gives grep dozens of files, without the
> fork and exec overhead.
>
> But there is a difference, if you call grep on more than one
> file, the filename is prefixed to the search results. If you
> don't want this, use:
>
> find . -type f -print0 | xargs -0 cat | grep "thing-to-find"
And there's the opposite problem -- if you do want the name
and you're using xargs to insure you get it, you might not if
the last invocation of "grep" is made with just a since file.
In which case you might do something like
find . -type f -print | xargs grep foo /dev/null
The extra /dev/null makes it so that grep always has two files
to process. This is really handy for people who don't have a
grep which includes an option to include the file name
regardless of the number of arguments.
--
Julianne Frances Haugh Life is either a daring adventure
txjulie at austin.rr.com or nothing at all.
-- Helen Keller
More information about the Techtalk
mailing list