GNU bug report logs - #35337
Document the recommended way to get the :0s out of -c output

Previous Next

Package: grep;

Reported by: 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>

Date: Sat, 20 Apr 2019 12:22:03 UTC

Severity: wishlist

Full log


View this message in rfc822 format

From: 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>
To: 35337 <at> debbugs.gnu.org
Subject: bug#35337: Document the recommended way to get the :0s out of -c output
Date: Sat, 20 Apr 2019 20:13:23 +0800
Boy they really blew it when they invented -c,
   (info "(grep) General Output Control")

  ‘-c’
  ‘--count’
       Suppress normal output; instead print a count of matching lines for
       each input file.  With the ‘-v’ (‘--invert-match’) option, count
       non-matching lines.  (‘-c’ is specified by POSIX.)

Who in the world ever wants to know about the zero match counts (:0)? ;-)
OK, well then add some extra switch for the rest of us... or at least the INFO
page should mention how the pros filter them out.

#1
time find * -name \*.html | xargs grep -l staticmap | xargs grep -c staticmap | head -n 3
location/directions/zaokeng.html:1
location/yaokeng_road.html:1
location/yaokeng_road2.html:1

real	0m0.015s
user	0m0.013s
sys	0m0.002s

#2
time find * -name \*.html | xargs grep -c staticmap | grep -v :0$   | head -n 3
comm/air/m750/trail.html:1
comm/air/m750/index.html:1
geo/house_numbering/taizhong/dongshi/index.html:1

real	0m0.017s
user	0m0.011s
sys	0m0.004s

(#1 is a big waste, but the real time is randomly a little shorter, as
it takes larger inputs so really see the difference.)

Anyway I've never ever wanted the :0s.

Wait! Maybe "-cl" or "-lc" will give us what we want!
Alas, they are just equivalent to "-l".
(As I suppose that fact is not documented, perhaps it could be given a
new (non-backwardly compatible, alas) definition...)




This bug report was last modified 6 years and 57 days ago.

Previous Next


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