Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #223946

Re: one liner, how do you know which match happened ...

From tomas@tuxteam.de
Newsgroups linux.debian.user
Subject Re: one liner, how do you know which match happened ...
Date 2020-06-24 13:00 +0200
Message-ID <Albih-2z4-1@gated-at.bofh.it> (permalink)
References <AjIV3-6Jq-1@gated-at.bofh.it> <AjJxL-7bY-3@gated-at.bofh.it> <AlaYV-2r5-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Wed, Jun 24, 2020 at 12:33:19PM +0200, Albretch Mueller wrote:
> > "grep -l" will stop at the first hit, so even if you could ask
> > grep which one of the alternatives it found, it'll miss Hegel
> > in a file where Kant figures first. Is that what you want?
> 
>  Yes, I am fine with that. I include the matches in the Array in a way
> that the first one is the most important to me anyway, but I need to
> know which one, which I think should be someone possible, since grep
> must go through the array using some index, no?

OK, if you just want the first hit, there is "--max-count" (aka "-m"),
which you can use with the combined regular expression. This (given
the value 1) will spit out the first matching line, which you can
then post-process to extract the exact match.

Post-processing is left as an exercise to the reader :-)

That should be about as fast as "grep -l" can get, take or give.

Cheers
-- tomás

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

one liner, how do you know which match happened ... Albretch Mueller <lbrtchx@gmail.com> - 2020-06-20 12:30 +0200
  Re: one liner, how do you know which match happened ... <tomas@tuxteam.de> - 2020-06-20 13:10 +0200
    Re: one liner, how do you know which match happened ... Albretch Mueller <lbrtchx@gmail.com> - 2020-06-24 12:40 +0200
      Re: one liner, how do you know which match happened ... tomas@tuxteam.de - 2020-06-24 13:00 +0200
        Re: one liner, how do you know which match happened ... Greg Wooledge <wooledg@eeg.ccf.org> - 2020-06-24 14:20 +0200
          Re: one liner, how do you know which match happened ... Albretch Mueller <lbrtchx@gmail.com> - 2020-06-24 17:30 +0200
  Re: one liner, how do you know which match happened ... David Wright <deblis@lionunicorn.co.uk> - 2020-06-20 16:40 +0200
  Re: one liner, how do you know which match happened ... David Christensen <dpchrist@holgerdanske.com> - 2020-06-20 22:30 +0200
  Re: one liner, how do you know which match happened ... davidson <davidson@freevolt.org> - 2020-06-20 23:10 +0200
    Re: one liner, how do you know which match happened ... davidson <davidson@freevolt.org> - 2020-06-20 23:30 +0200
      Re: one liner, how do you know which match happened ... Klaus Singvogel <deb-user-ml@singvogel.net> - 2020-06-21 01:10 +0200
  Re: one liner, how do you know which match happened ... Greg Wooledge <wooledg@eeg.ccf.org> - 2020-06-22 13:50 +0200

csiph-web