patchgrep - Patches: patch #7577, `grep -lc' to show only matching...

 
 

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

patch #7577: `grep -lc' to show only matching files

Submitted by:  Santiago Ruano Rincón <santiago>
Submitted on:  Wed 13 Jul 2011 11:56:25 PM UTC  
 
Category: NonePriority: 5 - Normal
Status: In ProgressPrivacy: Public
Assigned to: NoneOpen/Closed: Open

Wed 10 Aug 2011 07:17:37 PM UTC, comment #4:

Two people filled different bugs in debian asking for the same behavior from grep -lc, and, with my user's hat put on, I found the combination of --count and --files-with-matches clear. grep's man page doesn't say that those options only print matching count or file' names, as grep --help tries to say. Man page either says that those control output options cannot be used together (Maybe it should?).

However, in the name of standards, I'd prefer '-c --min-count' to achieve that behavior. So I agree with you, and this patch shouldn't be considered.

Santiago

Santiago Ruano Rincón <santiago>
Thu 14 Jul 2011 09:07:52 AM UTC, comment #3:

I'm inclined of including https://savannah.gnu.org/patch/index.php?6588 instead, with a -M command line so that you can achieve the result with grep -cM1. This has the advantage that the interaction with -v is clearer, too.

At the same time, -lc and -Lc could give an error.

Paolo Bonzini <bonzini>
Thu 14 Jul 2011 09:05:06 AM UTC, comment #2:

I don't understand what you mean by "garbled output from both options". "grep -lc" here gives exactly the same output as "grep -l". I understand why the patch is nice to have, but personally I would never have thought of specifying them together. :)

Also the help shows they are contradicting:

-l, --files-with-matches only print FILE names containing matches
-c, --count only print a count of matching lines per FILE

(emphasis on "only" added). Right now, my acceptance of the patch is conditioned on tweaking the help text or documentation to make the expected behavior clear.

Paolo Bonzini <bonzini>
Thu 14 Jul 2011 12:00:50 AM UTC, comment #1:

According to POSIX,
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/grep.html
-c and -l cannot portably be used together. But we could certainly support it as a GNU extension. Did you have a patch already in mind?

Eric Blake <ericb>
Project Member
Wed 13 Jul 2011 11:56:25 PM UTC, original submission:

Peter Samuelson has submitted a patch to Debian to modify the behavior of `grep -lc'. Copying what he wrote in http://bugs.debian.org/76011

-----------------------------------------------------------------

Okay, grep has two very useful options, -l and -c:

-l, --files-with-matches only print FILE names containing matches
-c, --count only print a count of matching lines per FILE

It seems only logical that 'grep -lc' would count the matching lines per file, but skip files with no matches. Obvious, right? (: But the status quo is that 'grep -lc' gives garbled output from both options, i.e. "undefined behavior".

Fortunately, it's a simple change. Would seven lines of source bloat be considered unacceptible? Note that this change isn't just for theoretical consistency -- I find it very practical. Because otherwise I am forever saying

grep -c ..... | grep -v :0

-----------------------------------------------------------------

I think his patch is correct and useful. Could you please consider this patch?

Thanks,

Santiago

Santiago Ruano Rincón <santiago>

 

Attached Files
file #23650:  grep-lc.patch added by santiago (1kB - text/x-diff)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by bonzini (Posted a comment)
  • -unavailable- added by ericb (Posted a comment)
  • -unavailable- added by santiago (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 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 14 Jul 2011 09:05:06 AM UTCbonziniStatusNone=>In Progress
    Wed 13 Jul 2011 11:56:25 PM UTCsantiagoAttached File-=>Added grep-lc.patch, #23650

    Back to the top


    Powered by Savane 3.1-cleanup