GNU bug report logs - #68989
grep -m[2+] > /dev/null

Previous Next

Package: grep;

Reported by: Grisha Levit <grishalevit <at> gmail.com>

Date: Thu, 8 Feb 2024 08:39:01 UTC

Severity: normal

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#68989: closed (grep -m[2+] > /dev/null)
Date: Fri, 09 Feb 2024 09:09:02 +0000
[Message part 1 (text/plain, inline)]
Your message dated Fri, 9 Feb 2024 01:08:24 -0800
with message-id <838e4b9e-d387-4f65-8b87-6c3769cffc34 <at> cs.ucla.edu>
and subject line Re: bug#68989: grep -m[2+] > /dev/null
has caused the debbugs.gnu.org bug report #68989,
regarding grep -m[2+] > /dev/null
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
68989: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=68989
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Grisha Levit <grishalevit <at> gmail.com>
To: bug-grep <at> gnu.org
Subject: grep -m[2+] > /dev/null
Date: Thu, 8 Feb 2024 03:37:24 -0500
[Message part 3 (text/plain, inline)]
This example file will require multiple reads:

$ printf '%07d\n' {0..98304} > txt

When limiting the match count to 1, the input offset is correctly restored
before grep exits,  no matter the output:

$ { grep -m1 . >/dev/zero; head -n1; } < txt
0000001
$ { grep -m1 . >/dev/null; head -n1; } < txt
0000001

If the count is 2 or higher, this also works, unless the output is being
discarded to /dev/null -- in this case not only is the input offset not
restored, but the entire file is consumed:

$ { grep -m2 . >/dev/zero; head -n1; } < txt
0000002
$ { grep -m2 . >/dev/null; head -n1; } < txt
$
[Message part 4 (text/html, inline)]
[Message part 5 (message/rfc822, inline)]
From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Grisha Levit <grishalevit <at> gmail.com>
Cc: 68989-done <at> debbugs.gnu.org
Subject: Re: bug#68989: grep -m[2+] > /dev/null
Date: Fri, 9 Feb 2024 01:08:24 -0800
[Message part 6 (text/plain, inline)]
Thanks for the bug report. I installed the attached patch; please give 
it a try.
[0001-grep-fix-grep-m2-pattern-file-dev-null.patch (text/x-patch, attachment)]

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

Previous Next


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