buggrep - Bugs: bug #31702, command line option '--include'...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #31702: command line option '--include' acts as '--exclude'

Submitted by:  Kevin Hunter <hunteke>
Submitted on:  Thu 18 Nov 2010 10:26:10 PM UTC  
 
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: Duplicate
Privacy: PublicAssigned to: None
Open/Closed: Closed

Fri 19 Nov 2010 03:33:52 PM UTC, comment #3:

Duplicate of #29876, and already fixed upstream.

Eric Blake <ericb>
Project Member
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.)

Kevin Hunter <hunteke>
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.

Stepan Kasal <kasal>
Project Member
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?

Kevin Hunter <hunteke>

 

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by ericb (Posted a comment)
  • -unavailable- added by kasal (Posted a comment)
  • -unavailable- added by hunteke (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Fri 19 Nov 2010 03:34:05 PM UTCericbOpen/ClosedOpen=>Closed
    Fri 19 Nov 2010 03:33:52 PM UTCericbStatusConfirmed=>Duplicate
    Fri 19 Nov 2010 02:29:37 PM UTCkasalStatusNone=>Confirmed

    Back to the top


    Powered by Savane 3.1-cleanup1