bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#68989: grep -m[2+] > /dev/null


From: Grisha Levit
Subject: bug#68989: grep -m[2+] > /dev/null
Date: Thu, 8 Feb 2024 03:37:24 -0500

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
$


reply via email to

[Prev in Thread] Current Thread [Next in Thread]