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


Groups > linux.debian.user > #248679

Re: grep: show matching line from pattern file

From duh <fill_in_the_blanks@email.com>
Newsgroups linux.debian.user
Subject Re: grep: show matching line from pattern file
Date 2022-06-02 21:20 +0200
Message-ID <EtYwp-269V-3@gated-at.bofh.it> (permalink)
References <EsaLo-XqP-13@gated-at.bofh.it> <EsqQ9-17ej-3@gated-at.bofh.it> <EsrsR-17qm-13@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On 5/29/22 9:44 AM, David Wright wrote:
> On Sun 29 May 2022 at 15:02:35 (+0200), Jörg-Volker Peetz wrote:
>> Jim Popovitch wrote on 28/05/2022 21:40:
>>> Not exactly Debian specific, but hoping that someone here can help.
>>>
>>> I have a file of regex patterns and I use grep like so:
>>>
>>>      ~$ grep -f patterns.txt /var/log/syslog
>>>
>>> What I'd like to get is a listing of all lines, specifically the line
>>> numbers of the regexps in patterns.txt, that match entries in
>>> /var/log/syslog.   Is there a way to do this?
>> How about this:
>>
>> $ grep -of patterns.txt /var/log/syslog.1 | grep -n -f - patterns.txt
> That will only work for literal patterns, not regex ones.
>
> Cheers,
> David.
>

I may be missing a lot but I will risk throwing in my 2 cents (which is
no longer worth the proverbial amount with

the current inflation)


$cat -n /var/log/syslog | grep warn

and it found "warn" in the syslog file and provided line numbers. I have
not used the -f option

(but am now aware of it in the pastfrom your post -- thank you. Might
file that away for future use but will not press

my luck at the moment).

My approach  saves me the effort of writing a scriptl. Ahh, the Perl
philosophy of "there is more than one way to do it".

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


Thread

grep: show matching line from pattern file Jim Popovitch <jim@k4vqc.com> - 2022-05-28 22:00 +0200
  Re: grep: show matching line from pattern file The Wanderer <wanderer@fastmail.fm> - 2022-05-28 22:10 +0200
    Re: grep: show matching line from pattern file Greg Wooledge <greg@wooledge.org> - 2022-05-28 23:20 +0200
      Re: grep: show matching line from pattern file The Wanderer <wanderer@fastmail.fm> - 2022-05-28 23:30 +0200
      Re: grep: show matching line from pattern file Jim Popovitch <jim@k4vqc.com> - 2022-05-29 19:50 +0200
      Re: grep: show matching line from pattern file Will Mengarini <seldon@eskimo.com> - 2022-06-03 00:30 +0200
        Re: grep: show matching line from pattern file David Christensen <dpchrist@holgerdanske.com> - 2022-06-03 01:00 +0200
          Re: grep: show matching line from pattern file Will Mengarini <seldon@eskimo.com> - 2022-06-03 02:20 +0200
  Re: grep: show matching line from pattern file Jörg-Volker Peetz <jvpeetz@web.de> - 2022-05-29 15:10 +0200
    Re: grep: show matching line from pattern file David Wright <deblis@lionunicorn.co.uk> - 2022-05-29 15:50 +0200
      Re: grep: show matching line from pattern file duh <fill_in_the_blanks@email.com> - 2022-06-02 21:20 +0200
        Re: grep: show matching line from pattern file Greg Wooledge <greg@wooledge.org> - 2022-06-02 21:20 +0200
          Re: grep: show matching line from pattern file Richard Hector <richard@walnut.gen.nz> - 2022-06-04 05:00 +0200

csiph-web