GNU bug report logs - #27931
grep -o fails to count empty lines (Debain Bug #532541)

Previous Next

Package: grep;

Reported by: "Santiago R.R." <santiagorr <at> riseup.net>

Date: Thu, 3 Aug 2017 13:29:02 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 27931 in the body.
You can then email your comments to 27931 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

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


Report forwarded to bug-grep <at> gnu.org:
bug#27931; Package grep. (Thu, 03 Aug 2017 13:29:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Santiago R.R." <santiagorr <at> riseup.net>:
New bug report received and forwarded. Copy sent to bug-grep <at> gnu.org. (Thu, 03 Aug 2017 13:29:02 GMT) Full text and rfc822 format available.

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

From: "Santiago R.R." <santiagorr <at> riseup.net>
To: bug-grep <at> gnu.org
Cc: 532541 <at> bugs.debian.org
Subject: grep -o fails to count empty lines (Debain Bug #532541)
Date: Thu, 3 Aug 2017 15:28:14 +0200
(Sorry if it's already filed, but I am unable to find it in the
bug archives)

Hi,

I'd like to forward this bug reported to Debian some years ago.
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=532541
It still happens in 3.1.

Quoting the original report:

When grepping for empty lines in a text file, grep works correctly in
most cases:

~$ grep ^$ myfile.txt 





~$ grep -n ^$ myfile.txt 
11:
15:
19:
21:
22:

However the -o option, which is supposed to return only the matching
parts of the search, fails:

~$ grep -o ^$ myfile.txt 
~$ grep -no ^$ myfile.txt
~$ 


Thanks,

Santiago




Reply sent to Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility. (Thu, 03 Aug 2017 20:18:02 GMT) Full text and rfc822 format available.

Notification sent to "Santiago R.R." <santiagorr <at> riseup.net>:
bug acknowledged by developer. (Thu, 03 Aug 2017 20:18:03 GMT) Full text and rfc822 format available.

Message #10 received at 27931-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: "Santiago R.R." <santiagorr <at> riseup.net>, 27931-done <at> debbugs.gnu.org
Cc: Greg Trounson <gregt <at> maths.otago.ac.nz>, Paolo Bonzini <bonzini <at> gnu.org>,
 Kai YU <yukai <at> nlsde.buaa.edu.cn>, 532541 <at> bugs.debian.org
Subject: Re: bug#27931: grep -o fails to count empty lines (Debain Bug #532541)
Date: Thu, 3 Aug 2017 13:16:52 -0700
[Message part 1 (text/plain, inline)]
On 08/03/2017 06:28 AM, Santiago R.R. wrote:
> the -o option, which is supposed to return only the matching
> parts of the search, fails:

It's not failing. It's behaving as documented: -o outputs only nonempty 
matches. Otherwise, commands like 'grep -o "a*"' would output a separate 
line for each byte in the input. Although this behavior for -o is 
longstanding and is documented in the manual, it's not in the grep 
--help output so that's an oversight. I installed the attached to fix 
grep --help, and am closing the bug report on the GNU side.

Users who want to match empty lines can use 'grep "^$"', which is what 
I'd expect them to do anyway (-o would be superfluous there even if it 
included empty matches).

[0001-doc-improve-o-help.patch (text/x-patch, attachment)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 01 Sep 2017 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 7 years and 295 days ago.

Previous Next


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