On Mon, Feb 21, 2011 at 10:00:21PM -0430, Andres Perera wrote: > On Mon, Feb 21, 2011 at 7:01 PM, Philip Guenther <guent...@gmail.com> wrote: > > On Mon, Feb 21, 2011 at 2:30 PM, Fred Crowson <open...@crowsons.net> wrote: > >> On 02/21/11 15:54, Alexander Schrijver wrote: > > ... > >>> grep(1) only prints the filename when it receives more then 1 filename as > >>> arguments. Thus, when you do this: > >>> > >>> $ find . -name '*.c' -exec grep bla {} \; > >>> > >>> It doesn't print the filename. > >>> > >>> But when you use xargs(1), like Bret suggests it does. > >> > >> $ find . -name "*.php" -exec grep blah {} \; -print > >> > >> Will print the file name after the line that grep matches. > > > > The other classical solution is to always pass multiple filenames by > > including a /dev/null argument: > > > > B find . -name '*.c' -exec grep bla {} /dev/null \; > > > > That works with the xargs case too: > > > > B find . -name '*.c' -print0 | xargs -0 grep bla /dev/null > > these two ugly hacks and the the redundant flag have been sought while > what's natural has been overlooked > > find . -name '*.c' -exec awk '/bla/ {print FILENAME $0}'
my that's awkward. > why complicate grep? --patrick "Anybody has a right to evade taxes if he can get away with it. No citizen has a moral obligation to assist in maintaining his government." -- J.P. Morgan