Subject: bug#70540: grep -c -r | grep -v ':0$'

From: "Dale R. Worley" <[email-masked]>
Date: Thu, 25 Apr 2024 16:30:01 -0400

Dennis Clarke via Bug reports for GNU grep <[email-masked]> writes:
> Perhaps a specific example would be helpful.

My most common case is something like

    grep -c --files-with-match 'some fragment of a command' ~/temp/shell.10??

which is searching the log files of my old shell sessions to find the
most recent session that has "many" uses of "some fragment of a
command".  Often, because I want to copy-modify-paste that command to
use in a current shell session.  Conceptually, the search process is:
find all files that mention the command, sort them by number of uses of
the command, then look at the contents of the one or two files with the
*most* uses (because there often are accidental matches in session logs
that don't "really" use the command).  Given that my desired command is
unlikely to output more than 5 or so lines, this patch makes that
process straightforward.

Another case is

    grep -c --files-with-match variable_name ~/bash-5.5.17

where I want to first look into the files that most often mention
variable_name to see exactly how it is used.

If these weren't ad-hoc activities, I would construct a careful pipeline
like

    grep -c -r pattern directory | sort -t: -k2,2r | head -n3

but for ad-hoc use, it seems to me that it's sensible and convenient to
make the combination -c -l do what it intuitively "ought" to do, given
that that change would be upward-compatible with Posix.

Dale