GNU bug report logs - #70540
grep -c -r | grep -v ':0$'

Previous Next

Package: grep;

Reported by: "Dale R. Worley" <worley <at> alum.mit.edu>

Date: Tue, 23 Apr 2024 18:34:13 UTC

Severity: normal

Full log


Message #17 received at 70540 <at> debbugs.gnu.org (full text, mbox):

From: "Dale R. Worley" <worley <at> alum.mit.edu>
To: Dennis Clarke <dclarke <at> blastwave.org>
Cc: 70540 <at> debbugs.gnu.org
Subject: Re: bug#70540: grep -c -r | grep -v ':0$'
Date: Thu, 25 Apr 2024 16:30:01 -0400
Dennis Clarke via Bug reports for GNU grep <bug-grep <at> gnu.org> 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




This bug report was last modified 1 year and 47 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.