Fri 19 Nov 2010 02:36:57 PM UTC, comment #2:
You are, of course, correct. I should be using find. And, in fact, that's what I did after I realized that grep wasn't behaving like I thought it should.
However, for the uninitiated, find is ... a bit of a trek.
I appreciate your attention to this detail, as while the --{in,ex}clude options are meant to be used in tandem with -r, I think a single directory test to make sure one knows what they are doing is a valid "does it work?" test.
Tangentially, do you think a couple of 'find | xargs grep' examples in the man page would be useful? I would be happy to craft a couple. I just know that I only recently (last year or so) started really using find, because I just didn't know how to use it. Examples in, for example, the man page of grep, would have been very helpful. (But, I risk littering this bug with non-bug discussion, so I'll leave it at that.)
|
Fri 19 Nov 2010 02:29:37 PM UTC, comment #1:
The options --include and --exclude were designed as an extension of the "recursive search" feature, option -r.
In that context, it works as expected:
grep main . -r --include="*.c"
grep main . -r --exclude="*.c"
If you want more flexibility, the Unix way is to use the proper tool: "find" is designed to search for files:
find -name '*.c' | xargs grep main
find ! -name '*.c' | xargs grep main
But back to your report:
yes, it seems that at --include combined with -r does nto behave sensibly.
|
Thu 18 Nov 2010 10:26:10 PM UTC, original submission:
I've read the pertinent areas of the man page a couple of times, but I may yet just not be understanding something. However, it appears that --include acts the same as --exclude. Test case:
-----
$ grep --version | head -1
GNU grep 2.6.3
$ dpkg -l | grep grep
ii grep 2.6.3-3 GNU grep, egrep and fgrep
$ mkdir test; cd test
$ cat > test.c
#include <stdio.h>
int main ( ) {
printf( "Test\n" );
return ( 0 );
}
$ ln test.c test.cxx
$ ln test.c test.cpp
$ ls
test.c test.cpp test.cxx
$ grep main * --exclude="*.c"
test.cpp:int main ( ) {
test.cxx:int main ( ) {
$ grep main * --include="*.c"
test.cpp:int main ( ) {
test.cxx:int main ( ) {
-----
Am I missing something really simple?
|