Sometimes we need to use another file which contains a multiple line that
we want to use as input pattern
example:
You have a.txt
a
b
c
d
e
And you want to search a
, c
, e
.
This case you can create input.txt
a
c
e
and use this command
grep -f -F input.txt a.txt
If the input txt is a list of regex you can remove the -F
option.
-F, --fixed-strings
Interpret PATTERNS as fixed strings, not regular expressions.
Top comments (1)
This is an absolutely brilliant feature. I use it all the time to find all the lines in file A that aren't in (ie
grep -v
) file B. One caveat is that on some platforms (yes, I'm glaring at you #OpenBSD) the file of patterns can't be empty, so the script in which I use it does anecho nonsense-that-will-never-appear-in-the-real-world >> thefile
before using it.