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

Re: grep: show matching line from pattern file




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".



Reply to: