grep annoyance!

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


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".

Austin

Alan Dayley wrote:
> GNU grep has annoyed me for a very long time for this one "fault" and it
> happened again just now.  I had to whine about it.
> 
> - Suppose I have a directory structure like so:
> project1---ui------frame.c
>          |       |-enter.c
>          |       \-ui.h
>          |-logic---main.c
>          |       |-transaction.c
>          |       \-main.h
>          |-README
>          \-COPYING
> 
> - Suppose I want to do a grep seach of all the .c files for "string"
> 
> I go to the project1 directory and issue the command and get this result:
> 
> $grep -r string *.c
> grep: *.c: No such file or directory
> $
> 
> The Annoyance: The '-r' option is supposed to recurse the subdirectories
> in the tree.  BUT, it fails and stops the search because my current
> directory, project1, does not have any files that match '*.c'  It does not
> recurse!
> 
> I have gotten around this in the past by doing 'touch bogus.c' in the
> current directory so that it will not fail and will start recursing.  But
> that is a lousy workaround.
> 
> Is there a option to grep that I just don't understand yet that will make
> grep recurse even if the current directory doesn't have a match on the
> file expression?
> 
> Alan
> 
> 
> 
> _______________________________________________
> PLUG-devel mailing list  -  PLUG-devel@lists.PLUG.phoenix.az.us
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-devel