Re: grep: show matching line from pattern file
On Thu, Jun 02, 2022 at 03:12:23PM -0400, duh wrote:
> > > Jim Popovitch wrote on 28/05/2022 21:40:
> > > > 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?
> $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
You're getting the line numbers from the log file. The OP wanted the line
numbers of the patterns in the -f pattern file.
Why? I have no idea. There is no standard option to do this, because
it's not a common requirement. That's why I wrote one from scratch
in perl.
Reply to: