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:  22  
 
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: Need Info
Privacy: PublicAssigned to: None
Open/Closed: Open

Sat 21 Sep 2013 05:54:10 AM UTC, comment #2:

For this bug (#33080) it seems like -o would have to be taken into consideration before -c.
For bug #23635 Anonymous would like grep -C2;grep -C2 -v to output every line of the file. Currently it may include duplicates. This is similar and -C would have to be taken into consideration before -v.
If I'm not mistaken -C (as mentioned in #23635) and -o are gnu extensions but i haven't looked at the source and have no intention to. Only based off the results i assume gnu extensions are done last.
Here is another proposal for intuitive operation. Currently grep -ov will always return nothing which is not very useful. But what would be useful would be to return the nonmatching portion of the matching lines. This would give functionality, similar in many ways to #29827 but that is overcomplicated in my opinion. I am not prepared to write a patch at this time.
I hope you will understand and respond.

jikszzve <jikszzve>
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 22 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
    Sat 21 Sep 2013 05:56:59 AM UTCjikszzveCarbon-Copy-=>Added jikszzve
    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