GNU bug report logs -
#75197
[Feature Request] Support 'grep -A' without number to show all lines after match
Previous Next
To reply to this bug, email your comments to 75197 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-grep <at> gnu.org
:
bug#75197
; Package
grep
.
(Mon, 30 Dec 2024 12:09:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
KMRH <kmrh47 <at> proton.me>
:
New bug report received and forwarded. Copy sent to
bug-grep <at> gnu.org
.
(Mon, 30 Dec 2024 12:09:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Package: grep
Severity: wishlist
Dear Maintainers,
I would like to request a feature enhancement for the grep tool.
Feature Request
Allow the command 'grep -A' (without specifying a number) to default to showing all lines after a match, instead of erroring out. This would be conceptually equivalent to something like using a very large number ('grep -A 999999 <pattern>'), but without having to manually pick a placeholder length.
Current Behavior
$ grep -A <pattern>
grep: <pattern>: Invalid context length argument
Proposed Behavior
$ grep -A <pattern> # show all lines after match
Rationale
- Intuitive defaults: If no numeric limit is specified, show everything after the match.
- Cleaner syntax: Avoids the arbitrary use of large numbers.
- Unix philosophy: Simple, predictable defaults that reduce friction.
- Alternative approach: If there’s concern about backward compatibility, consider a more explicit flag like '-A all'
I acknowledge that some scripts may rely on the current error behavior for an empty '-A' argument. However, I believe that in most cases it would not cause significant breakage. If necessary, we could introduce a distinct option to avoid disrupting existing usage.
Thank you for considering this enhancement.
Best regards,
Karsten Holmøe
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-grep <at> gnu.org
:
bug#75197
; Package
grep
.
(Mon, 30 Dec 2024 18:54:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 75197 <at> debbugs.gnu.org (full text, mbox):
On 2024-12-30 03:37, KMRH via Bug reports for GNU grep wrote:
> Allow the command 'grep -A' (without specifying a number) to default to showing all lines after a match
We couldn't do that as-is, as 'grep -A 1' is equivalent to 'grep -A1'
and people rely on that.
'grep -A 99999999999999999999999999999999999999999' does what you want
already, even if 99999999999999999999999999999999999999999 is too big to
fit into a machine word. Is that good enough? It would save your having
to wait for the next grep release....
Alternatively, I suppose we could add syntax like 'grep -A Inf' to do
what's requested, where "Inf" is short for infinity.
Information forwarded
to
bug-grep <at> gnu.org
:
bug#75197
; Package
grep
.
(Mon, 30 Dec 2024 19:46:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 75197 <at> debbugs.gnu.org (full text, mbox):
Paul Eggert <eggert <at> cs.ucla.edu> wrote:
> Alternatively, I suppose we could add syntax like 'grep -A Inf' to do
> what's requested, where "Inf" is short for infinity.
And just wait, as soon as you do that, someone will want
grep -A NaN
:-) :-) :-)
Arnold
Information forwarded
to
bug-grep <at> gnu.org
:
bug#75197
; Package
grep
.
(Tue, 31 Dec 2024 07:40:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 75197 <at> debbugs.gnu.org (full text, mbox):
Or, for us old farts who have been using 'sed' for a half century, if I wanted to print the lines in a file starting with the line matching a certain pattern, through the remaining lines of the file, I'd use:
sed -n '/pattern/,$/p' < file
Then I wouldn't have to worry whether or not the 'grep' command I was using would lose it's lunch trying to parse '9999999999999999999999', though, granted, every executable 'grep' binary I happen to have on my disk, a couple dozen of them going back over 20 years, all handle the forty-nine 9's I just tested, HOWEVER the busybox 0.51 grep source code circa 2001 I have at hand will fail if strtoul of the numeric argument to "-A" overflows, returning ULONG_MAX with errno of ERANGE, and likely some older variants of grep would also fail, _and_
I wouldn't have to worry that my 'magic' number wasn't big enough for every ordinary, already written to disk, file that I might be reading, _and_
I could run this off a pipe that never ended with a normal closure of the input stream that would have sent an EOF to input stream of 'sed', but only ended with a signal or hardware stoppage, without worrying that I had not put enough nine's (9) in my number, _and_
I wouldn't have readers of that code wondering what that strange number was ... though, granted, I would have them doing 'man sed' ... about time in my book.
But, yes, as Paul Eggert notes, command line parsing of 'grep -A 123' would be ambiguous. Is "123" a filename, or a parameter to the "-A" argument?
--
Paul Jackson
jackson <at> fastmail.fm
This bug report was last modified 166 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.