Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grep finding which of the pattern ARE NOT in the file

Tags:

linux

grep

unix

I'm trying to find out (grep) which of my patterns from file don't appear in log file.
I have file input.txt which contains:

00123
00124
00125
00126

and log file 20210716.log

00123
a
b
c
d
00125
00126
xy
z
...
(tons of text)
...
00127

When using grep -f input.txt 20210716.log in output i get:

00123
00125
00126

How can i output patterns from input.txt that don't appear in log file?, so I would like to get:

00124
like image 959
Melcor11 Avatar asked Oct 16 '25 04:10

Melcor11


1 Answers

You may try this grep:

grep -vFf file.log input.txt

00124

Or else you can use awk like this:

awk 'NR == FNR {seen[$1]; next} !($0 in seen)' file.log input.txt

00124
like image 86
anubhava Avatar answered Oct 18 '25 22:10

anubhava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!