GNU bug report logs - #28304
Feature Request - Quit on Non Match

Previous Next

Package: grep;

Reported by: Adam Danischewski <adam.danischewski <at> gmail.com>

Date: Thu, 31 Aug 2017 14:44:02 UTC

Severity: wishlist

To reply to this bug, email your comments to 28304 AT debbugs.gnu.org.

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#28304; Package grep. (Thu, 31 Aug 2017 14:44:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Adam Danischewski <adam.danischewski <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-grep <at> gnu.org. (Thu, 31 Aug 2017 14:44:02 GMT) Full text and rfc822 format available.

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

From: Adam Danischewski <adam.danischewski <at> gmail.com>
To: bug-grep <at> gnu.org
Subject: Feature Request - Quit on Non Match
Date: Thu, 31 Aug 2017 10:43:30 -0400
[Message part 1 (text/plain, inline)]
I've been writing parsers and it would be really nice if grep could do the
following:

*grep --quit-nm 1 -Pno "^[ \t\f]*#.*$" <(sed -n '2,$p' gen_ent.bsh)*

If you:
*grep -m 1 -Pno "^[ \t\f]*#.*$" <(sed -n '2,$p' gen_ent.bsh)*

Only the first match of the header block gets printed, yet it would be nice
if grep in O(n), could simply be on the look out for the first failure to
match the -o context and quit at --quit-nm non-match occurrences.
[Message part 2 (text/html, inline)]

Information forwarded to bug-grep <at> gnu.org:
bug#28304; Package grep. (Thu, 31 Aug 2017 14:54:02 GMT) Full text and rfc822 format available.

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

From: arnold <at> skeeve.com
To: adam.danischewski <at> gmail.com, 28304 <at> debbugs.gnu.org
Subject: Re: bug#28304: Feature Request - Quit on Non Match
Date: Thu, 31 Aug 2017 08:53:30 -0600
Adam Danischewski <adam.danischewski <at> gmail.com> wrote:

> I've been writing parsers and it would be really nice if grep could do the
> following:
>
> *grep --quit-nm 1 -Pno "^[ \t\f]*#.*$" <(sed -n '2,$p' gen_ent.bsh)*
>
> If you:
> *grep -m 1 -Pno "^[ \t\f]*#.*$" <(sed -n '2,$p' gen_ent.bsh)*
>
> Only the first match of the header block gets printed, yet it would be nice
> if grep in O(n), could simply be on the look out for the first failure to
> match the -o context and quit at --quit-nm non-match occurrences.

I may be misunderstanding what you want, but something like

	awk '/pattern to match/ { print ; continue }
		{ exit 0}' file

might do what I think you want - exit on first non match.

If gawk can do the same matching you're doing with grep -Pno, that
is a different question.

HTH,

Arnold




Information forwarded to bug-grep <at> gnu.org:
bug#28304; Package grep. (Thu, 31 Aug 2017 17:51:02 GMT) Full text and rfc822 format available.

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

From: Adam Danischewski <adam.danischewski <at> gmail.com>
To: arnold <at> skeeve.com
Cc: 28304 <at> debbugs.gnu.org
Subject: Re: bug#28304: Feature Request - Quit on Non Match
Date: Thu, 31 Aug 2017 13:50:49 -0400
[Message part 1 (text/plain, inline)]
Yes, awk can handle it except for maybe very large files. I was trying to
keep it restricted to grep, grep is already counting matches with -m but
maybe GNU views this direction as becoming too programmatic from what the
original vision of grep is?

awk '{if($0~/^[ \t\f#]+/)print $0;else exit}' gen_ent.bsh

Thanks anyway,
 +AMD

On Thu, Aug 31, 2017 at 10:53 AM, <arnold <at> skeeve.com> wrote:

> Adam Danischewski <adam.danischewski <at> gmail.com> wrote:
>
> > I've been writing parsers and it would be really nice if grep could do
> the
> > following:
> >
> > *grep --quit-nm 1 -Pno "^[ \t\f]*#.*$" <(sed -n '2,$p' gen_ent.bsh)*
> >
> > If you:
> > *grep -m 1 -Pno "^[ \t\f]*#.*$" <(sed -n '2,$p' gen_ent.bsh)*
> >
> > Only the first match of the header block gets printed, yet it would be
> nice
> > if grep in O(n), could simply be on the look out for the first failure to
> > match the -o context and quit at --quit-nm non-match occurrences.
>
> I may be misunderstanding what you want, but something like
>
>         awk '/pattern to match/ { print ; continue }
>                 { exit 0}' file
>
> might do what I think you want - exit on first non match.
>
> If gawk can do the same matching you're doing with grep -Pno, that
> is a different question.
>
> HTH,
>
> Arnold
>
[Message part 2 (text/html, inline)]

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

Previous Next


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