grep annoyance!

Austin Godber plug-devel@lists.PLUG.phoenix.az.us
Fri Apr 15 11:29:02 2005


ted@gould.cx wrote:
> On Fri, 15 Apr 2005, Austin Godber wrote:
> 
>>I don't know if there is an option for grep ... it would be nice ... but
>>you can use find's -exec feature in conjunction with grep like this:
>>
>>find . -iname "*.c" -exec grep include {} \;
>>
>>It will search below the current directory for any file ending in .c or
>>.C and grep anything it finds for the string "include".
> 
> What I dislike about that method is that it doesn't include the filename 
> of where it found the text.  I tend to use:
> 
> find . -name "*.c" | xargs grep include
> 
> 	--Ted

Good point.  I have never gotten comfortable with xargs.  But there is a
grep option (-H) to print the filename.  So:

find . -iname "*.c" -exec grep -H include {} \;

will take care of the filename problem.  Although I should probably
learn to use xargs better anyway.

Austin