Debian Bug report logs - #76011
"grep -lc" should Do The Right Thing

version graph

Package: grep; Maintainer for grep is Anibal Monsalve Salazar <anibal@debian.org>; Source for grep is src:grep.

Reported by: Peter Samuelson <peter@cadcamlab.org>

Date: Wed, 1 Nov 2000 07:03:01 UTC

Severity: wishlist

Tags: patch

Merged with 35516

Found in versions 2.4.2-1, 2.2-1

Forwarded to https://savannah.gnu.org/patch/?7577

Reply or subscribe to this bug.

Toggle useless messages

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-bugs-dist@lists.debian.org, Wichert Akkerman <wakkerma@debian.org>:
Bug#76011; Package grep. Full text and rfc822 format available.

Acknowledgement sent to Peter Samuelson <peter@cadcamlab.org>:
New Bug report received and forwarded. Copy sent to Wichert Akkerman <wakkerma@debian.org>. Full text and rfc822 format available.

Message #5 received at submit@bugs.debian.org (full text, mbox):

From: Peter Samuelson <peter@cadcamlab.org>
To: submit@bugs.debian.org
Subject: grep: [PATCH] "grep -lc" should Do The Right Thing
Date: Tue, 31 Oct 2000 23:59:06 -0600 (CST)
Package: grep
Version: 2.4.2-1
Severity: wishlist

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

to get the same result.

Thanks,
Peter


--- src/grep.c~	Tue Feb  1 23:49:07 2000
+++ src/grep.c	Tue Oct 31 23:42:44 2000
@@ -849,7 +849,7 @@
     status = count + 2;
   else
     {
-      if (count_matches)
+      if (count_matches && (count || (count_matches == 1)))
 	{
 	  if (out_file)
 	    printf ("%s%c", filename, ':' & filename_mask);
@@ -1365,6 +1365,13 @@
 	break;
       }
 
+  /* grep -cl means count lines but skip "xxx:0" */
+  if (count_matches == 1 && list_files == 1)
+    {
+      list_files = 0;
+      count_matches = -1;
+      done_on_match = 0;
+    }
   if (out_after < 0)
     out_after = default_context;
   if (out_before < 0)



Merged 35516 76011. Request was from Colin Watson <cjwatson@flatline.org.uk> to control@bugs.debian.org. Full text and rfc822 format available.

Changed Bug title. Request was from Colin Watson <cjwatson@flatline.org.uk> to control@bugs.debian.org. Full text and rfc822 format available.

Tags added: patch Request was from Colin Watson <cjwatson@flatline.org.uk> to control@bugs.debian.org. Full text and rfc822 format available.

Information forwarded to debian-bugs-dist@lists.debian.org, Robert van der Meulen <rvdm@debian.org>, grep@packages.qa.debian.org:
Bug#76011; Package grep. Full text and rfc822 format available.

Acknowledgement sent to Martin Michlmayr <tbm@cyrius.com>:
Extra info received and forwarded to list. Copy sent to Robert van der Meulen <rvdm@debian.org>, grep@packages.qa.debian.org. Full text and rfc822 format available.

Message #16 received at 76011@bugs.debian.org (full text, mbox):

From: Martin Michlmayr <tbm@cyrius.com>
To: Peter Samuelson <peter@cadcamlab.org>
Cc: 76011@bugs.debian.org
Subject: Re: grep: [PATCH] "grep -lc" should Do The Right Thing
Date: Mon, 12 Aug 2002 23:58:48 +0200
See http://bugs.debian.org/76011

* Peter Samuelson <peter@cadcamlab.org> [2000-10-31 23:59]:
>   -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
> 
> --- src/grep.c~	Tue Feb  1 23:49:07 2000
> +++ src/grep.c	Tue Oct 31 23:42:44 2000
> @@ -849,7 +849,7 @@

While your patch works with grep 2.4.x, it doesn't produce your
intended behavior with the new version 2.5.  Could you make a patch
against 2.5?

-- 
Martin Michlmayr
tbm@cyrius.com



Tags removed: patch Request was from Martin Michlmayr <tbm@cyrius.com> to control@bugs.debian.org. Full text and rfc822 format available.

Information forwarded to debian-bugs-dist@lists.debian.org, Robert van der Meulen <rvdm@debian.org>, grep@packages.qa.debian.org:
Bug#76011; Package grep. Full text and rfc822 format available.

Acknowledgement sent to Peter Samuelson <peter@cadcamlab.org>:
Extra info received and forwarded to list. Copy sent to Robert van der Meulen <rvdm@debian.org>, grep@packages.qa.debian.org. Full text and rfc822 format available.

Message #23 received at 76011@bugs.debian.org (full text, mbox):

From: Peter Samuelson <peter@cadcamlab.org>
To: 76011@bugs.debian.org
Subject: Re: grep: [PATCH] "grep -lc" should Do The Right Thing
Date: Mon, 12 Aug 2002 17:28:47 -0500
[Martin Michlmayr]
> While your patch works with grep 2.4.x, it doesn't produce your
> intended behavior with the new version 2.5.  Could you make a patch
> against 2.5?

Sure.  This one seems to work.

--- src/grep.c~	2002-03-13 08:49:52.000000000 -0600
+++ src/grep.c	2002-08-12 17:24:02.000000000 -0500
@@ -945,7 +945,7 @@
     status = count + 2;
   else
     {
-      if (count_matches)
+      if (count_matches && (count || (count_matches == 1)))
 	{
 	  if (out_file)
 	    printf ("%s%c", filename, ':' & filename_mask);
@@ -1626,14 +1626,23 @@
       }
 
   /* POSIX.2 says that -q overrides -l, which in turn overrides the
-     other output options.  */
+     other output options.  We violate this slightly by allowing -c
+     and -l to coexist (print 'file:count' but skip if count==0).  */
   if (exit_on_match)
-    list_files = 0;
-  if (exit_on_match | list_files)
     {
+      list_files = 0;
       count_matches = 0;
       done_on_match = 1;
     }
+  else if (list_files && count_matches)
+    {
+      list_files = 0;
+      count_matches = 2;
+      done_on_match = 0;
+    }
+  else if (list_files)
+    done_on_match = 1;
+
   out_quiet = count_matches | done_on_match;
 
   if (out_after < 0)



Tags added: patch Request was from Touko Korpela <tkorpela@phnet.fi> to control@bugs.debian.org. (Tue, 18 Sep 2007 13:03:04 GMT) Full text and rfc822 format available.

Information forwarded to debian-bugs-dist@lists.debian.org, Anibal Monsalve Salazar <anibal@debian.org>:
Bug#76011; Package grep. (Mon, 06 Jun 2011 23:09:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Santiago Ruano Rincón <santiago@debian.org>:
Extra info received and forwarded to list. Copy sent to Anibal Monsalve Salazar <anibal@debian.org>. (Mon, 06 Jun 2011 23:09:03 GMT) Full text and rfc822 format available.

Message #30 received at 76011@bugs.debian.org (full text, mbox):

From: Santiago Ruano Rincón <santiago@debian.org>
To: 76011-submitter@bugs.debian.org, 76011@bugs.debian.org
Subject: Closing
Date: Tue, 07 Jun 2011 00:12:57 +0200
Eleven years since the bug was filled, I'm working to close this bug,
but better late than never.

I've slightly modified your patch to match the current files in grep
structure. Please tell me if this would be correct:

--- a/src/main.c    2011-06-01 18:55:32.000000000 +0200
+++ b/src/main.c    2011-06-01 19:12:03.000000000 +0200
@@ -1267,7 +1267,7 @@
     status = count + 2;
   else
     {
-      if (count_matches)
+      if (count_matches && (count || (count_matches == 1)))
         {
           if (out_file)
             {
@@ -2088,14 +2088,23 @@
       }
 
   /* POSIX.2 says that -q overrides -l, which in turn overrides the
-     other output options.  */
+     other output options.  We violate this slightly by allowing -c
+     and -l to coexist (print 'file:count' but skip if count==0).  */
   if (exit_on_match)
-    list_files = 0;
-  if (exit_on_match | list_files)
     {
+      list_files = 0;
       count_matches = 0;
       done_on_match = 1;
     }
+  else if (list_files && count_matches)
+    {
+      list_files = 0;
+      count_matches = 2;
+      done_on_match = 0;
+    }
+  else if (list_files)
+    done_on_match = 1;
+
   out_quiet = count_matches | done_on_match;
 
   if (out_after < 0)

I've put the patch in debian's git repository in collab-maint
git://git.debian.org/git/collab-maint/grep.git , and upload a test
package to http://people.debian.org/~santiago/grep/  Could you please
try it out?

Thanks a lot, and really sorry for not taking care of this bug before,

Santiago






Message sent on to Peter Samuelson <peter@cadcamlab.org>:
Bug#76011. (Mon, 06 Jun 2011 23:09:04 GMT) Full text and rfc822 format available.

Reply sent to Santiago Ruano Rincón <santiago@debian.org>:
You have taken responsibility. (Thu, 14 Jul 2011 00:21:07 GMT) Full text and rfc822 format available.

Notification sent to Peter Samuelson <peter@cadcamlab.org>:
Bug acknowledged by developer. (Thu, 14 Jul 2011 00:21:07 GMT) Full text and rfc822 format available.

Message #38 received at 76011-close@bugs.debian.org (full text, mbox):

From: Santiago Ruano Rincón <santiago@debian.org>
To: 76011-close@bugs.debian.org
Subject: Bug#76011: fixed in grep 2.9-1
Date: Thu, 14 Jul 2011 00:17:34 +0000
Source: grep
Source-Version: 2.9-1

We believe that the bug you reported is fixed in the latest version of
grep, which is due to be installed in the Debian FTP archive:

grep_2.9-1.debian.tar.gz
  to main/g/grep/grep_2.9-1.debian.tar.gz
grep_2.9-1.dsc
  to main/g/grep/grep_2.9-1.dsc
grep_2.9-1_i386.deb
  to main/g/grep/grep_2.9-1_i386.deb
grep_2.9.orig.tar.gz
  to main/g/grep/grep_2.9.orig.tar.gz



A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 76011@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Santiago Ruano Rincón <santiago@debian.org> (supplier of updated grep package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@debian.org)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Format: 1.8
Date: Wed, 13 Jul 2011 20:02:15 -0400
Source: grep
Binary: grep
Architecture: source i386
Version: 2.9-1
Distribution: unstable
Urgency: low
Maintainer: Anibal Monsalve Salazar <anibal@debian.org>
Changed-By: Santiago Ruano Rincón <santiago@debian.org>
Description: 
 grep       - GNU grep, egrep and fgrep
Closes: 76011 624387
Changes: 
 grep (2.9-1) unstable; urgency=low
 .
   * 60-76011-main.c.patch: `grep -lc' does not show files with no occurrences.
     Thanks to Peter Samuelson. (Closes: #76011)
   * New upstream release.
     - Fixes locales and brackets-related bug (Closes: #624387)
   * Updating 80-587930-man-ere-reference.patch to add changes in info page
Checksums-Sha1: 
 f45998176b0d2936375d1d44ce1d20a9d4ca079a 1216 grep_2.9-1.dsc
 910ccb63f7436349c0bc6ae60f916a8cf938fcb8 1790291 grep_2.9.orig.tar.gz
 bbb77fdba15fe64ed4452d77e8852a7785b2220e 14119 grep_2.9-1.debian.tar.gz
 a11c8785928534b113cbc008e4e70be97a44b127 384620 grep_2.9-1_i386.deb
Checksums-Sha256: 
 40465273af0e40449609a66c0e2d88cd00f614cfe2d8a8f0045f2418a74f9617 1216 grep_2.9-1.dsc
 e9118eac72ecc71191725a7566361ab7643edfd3364869a47b78dc934a357970 1790291 grep_2.9.orig.tar.gz
 8d12345d77dbf8aac84c26618f07285c18a509dd084c9cdcf19fefb96e848320 14119 grep_2.9-1.debian.tar.gz
 f7b731a26dc39a92470aa98fd50a1bb29d2d9ae5f820bed062f0dfc5a7e7d8b0 384620 grep_2.9-1_i386.deb
Files: 
 af808562fbe907690f069481a76fc978 1216 utils required grep_2.9-1.dsc
 03e3451a38b0d615cb113cbeaf252dc0 1790291 utils required grep_2.9.orig.tar.gz
 5fd4f1530d0e28783c8be05b2e0ce952 14119 utils required grep_2.9-1.debian.tar.gz
 9ca17abbeef61c10f78b9b212fe5b8ce 384620 utils required grep_2.9-1_i386.deb

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iEYEARECAAYFAk4eM90ACgkQQUuEI2/szeA1lQCfVO8fUpLHXCrkk+hgCxc3OtRL
YD4AnRAXeZvbxYX5rDYbf/dl2V+s1+Ck
=Dlkf
-----END PGP SIGNATURE-----





Reply sent to Santiago Ruano Rincón <santiago@debian.org>:
You have taken responsibility. (Thu, 14 Jul 2011 00:21:07 GMT) Full text and rfc822 format available.

Notification sent to Raul <rdm@test.legislate.com>:
Bug acknowledged by developer. (Thu, 14 Jul 2011 00:21:07 GMT) Full text and rfc822 format available.

Information forwarded to debian-bugs-dist@lists.debian.org, Anibal Monsalve Salazar <anibal@debian.org>:
Bug#76011; Package grep. (Wed, 17 Aug 2011 23:27:43 GMT) Full text and rfc822 format available.

Acknowledgement sent to Santiago Ruano Rincón <santiago@debian.org>:
Extra info received and forwarded to list. Copy sent to Anibal Monsalve Salazar <anibal@debian.org>. (Wed, 17 Aug 2011 23:27:43 GMT) Full text and rfc822 format available.

Message #48 received at 76011@bugs.debian.org (full text, mbox):

From: Santiago Ruano Rincón <santiago@debian.org>
To: control@bugs.debian.org, 76011-submitter@bugs.debian.org, 76011@bugs.debian.org
Subject: reopening
Date: Thu, 18 Aug 2011 01:24:25 +0200
package grep
reopen 76011
forward 76011 https://savannah.gnu.org/patch/?7577
thanks

Upstream doesn't agree to apply this patch. Besides it doesn't comply
with POSIX standard, it doesn't work properly with with grep -Lc.
Upstreams proposes to use another aproach, introducing a new --min-count
[1] option, which mixed with -c, would have the same output.

[1] https://savannah.gnu.org/patch/index.php?6588

Cheers!

Santiago






Bug No longer marked as fixed in versions grep/2.9-1 and reopened. Request was from Debbugs Internal Request <owner@bugs.debian.org> to internal_control@bugs.debian.org. (Wed, 17 Aug 2011 23:27:45 GMT) Full text and rfc822 format available.

Message sent on to Peter Samuelson <peter@cadcamlab.org>:
Bug#76011. (Wed, 17 Aug 2011 23:27:50 GMT) Full text and rfc822 format available.

Set Bug forwarded-to-address to 'https://savannah.gnu.org/patch/?7577'. Request was from Santiago Ruano Rincón <santiago@debian.org> to control@bugs.debian.org. (Thu, 18 Aug 2011 12:18:44 GMT) Full text and rfc822 format available.

Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Sat Apr 19 03:07:16 2014; Machine Name: buxtehude.debian.org

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