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'

Submitter:  Kevin Hunter <hunteke>
Submitted:  Thu 18 Nov 2010 10:26:10 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Duplicate
Privacy:  Public Assigned 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>
Group 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>
Group 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>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2010-11-19 ericb Open/ClosedOpen Closed
    2010-11-19 ericb StatusConfirmed Duplicate
    2010-11-19 kasal StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-bb6a.
    Corresponding source code