buggrep - Bugs: bug #33080, combination of --count (-c) and...

 
 

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

bug #33080: combination of --count (-c) and --only-matching (-o)

Submitted by:  Seungbeom Kim <musiphil>
Submitted on:  Thu 14 Apr 2011 11:32:25 PM UTC  
Votes:  20  
 
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: Need Info
Privacy: PublicAssigned to: None
Open/Closed: Open

Tue 28 Jun 2011 12:30:02 PM UTC, comment #1:

I agree with the analysis, but an alternative is to just print an error. Any other opinions?

Paolo Bonzini <bonzini>
Thu 14 Apr 2011 11:32:25 PM UTC, original submission:

--only-matching (-o) causes grep to print all the matching parts separately, no matter how many times such parts occur on a single line. For example:

$ cat > test.txt
true true false
false true
false
true false true
$ grep --only-matching b test.txt
true
true
true
true
true

If you want to count how many matches you have, you naturally think you can use --count (-c). But you can't:

$ grep --only-matching --count true test.txt
3

You still get the number of "lines" that match the pattern, not how many "matches". The --only-matching option is effectively ignored, in a silent way.

This is counter-intuitive, when you consider that 'grep --count ...' is generally equivalent to 'grep ... | wc -l', which doesn't hold if --only-matching is used.

$ grep true test.txt | wc -l
3
$ grep --count true test.txt
3
$ grep --only-matching true test.txt | wc -l
5
$ grep --only-matching --count true test.txt
3

I suggest that grep --count should print the number of lines that would be printed without --count, whether or not --only-matching is used; that is, the number of lines that match the pattern without --only-matching, and the number of matches with --only-matching.

Seungbeom Kim <musiphil>

 

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 musiphil (Voted in favor of this item)
  • -unavailable- added by bonzini (Posted a comment)
  • -unavailable- added by musiphil (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 20 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 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sat 13 Aug 2011 08:54:49 PM UTCmusiphilCarbon-Copy-=>Added musiphil
    Tue 28 Jun 2011 12:30:02 PM UTCbonziniStatusNone=>Need Info

    Back to the top


    Powered by Savane 3.1-cleanup