Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 09 Jun 2008 17:24:54 +0300
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        freebsd-questions@freebsd.org
Subject:   Re: Grep Guru
Message-ID:  <87od6an0sp.fsf@kobe.laptop>
In-Reply-To: <20080608230712.GA24307@ayn.mi.celestial.com> (Bill Campbell's message of "Sun, 8 Jun 2008 16:07:12 -0700")
References:  <484C3CC4.7050107@webrz.net> <20080608221328.U9955@wojtek.tensor.gdynia.pl> <20080608225023.GD54922@ma.sigsys.de> <20080608230712.GA24307@ayn.mi.celestial.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 8 Jun 2008 16:07:12 -0700, Bill Campbell <freebsd@celestial.com> wrote:
> On Mon, Jun 09, 2008, Raphael Becker wrote:
>>On Sun, Jun 08, 2008 at 10:15:50PM +0200, Wojciech Puchar wrote:
>>> find . -type f -print0|xargs -0 grep <grepoptions> <text to search>
>>
>>There's no more need for find | xargs
>>
>>Try:
>>
>>find . -type -f -exec grep <grepoptions> <text to search> {} \+
>>
>>-exec foo {} \+ behaves like xargs foo
>>-exec foo {} \; exec foo for every file
>
> The issue here is that grep execs grep for each file found while
> xargs batches the files.

The \+ trick behaves like xargs, so this shouldn't be an issue :)

> This is of particular importance if one wants to see the file
> names in the output.

You can ensure the same even if xargs picks up a single file to grep
with

    xargs -0 grep pattern /dev/null

This will cost an open() / read() pair for each batch of files, but it
ensures that grep will always see at least two file names, and it should
print the filename of any matching files.




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