Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 8 Jun 2008 16:07:12 -0700
From:      Bill Campbell <freebsd@celestial.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: Grep Guru
Message-ID:  <20080608230712.GA24307@ayn.mi.celestial.com>
In-Reply-To: <20080608225023.GD54922@ma.sigsys.de>
References:  <484C3CC4.7050107@webrz.net> <20080608221328.U9955@wojtek.tensor.gdynia.pl> <20080608225023.GD54922@ma.sigsys.de>

next in thread | previous in thread | raw e-mail | index | archive | help
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.

This is of particular importance if one wants to see the file
names in the output.  In relation to this, if one wants to be
sure that grep always generates the file name, insure that it
always gets at least two files as arguments:

find . -type f -print0 | xargs -0 grep pattern /dev/null

FWIW, I have learned about gnu-grep's -r option reading this
thread, which I had not noticed previously.  I guess that just
goes to show that old habits die hard :-).

Bill
-- 
INTERNET:   bill@celestial.com  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
Voice:          (206) 236-1676  Mercer Island, WA 98040-0820
Fax:            (206) 232-9186

Good luck to all you optimists out there who think Microsoft can deliver
35 million lines of quality code on which you can operate your business.
   -- John C. Dvorak



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