How to Match Multiple Strings with grep
If you need to match a string in a file, then grep
is your friend.
An example of using grep
Let’s take a file called somefile.txt
We can look for the string something
in this file using grep
:
But what if we want to look for both something
and this
?
An example of using multiple grep
s
It’s pretty easy, we just pass the -E
flag, which is short for --extended-regexp
, and separate our strings with a pipe |
.
All the ways to use grep
multiple patterns
Multiples:
|
|
Search all text files:
|
|
Search all python files for wordA
and wordB
:
Show all the lines that do not match given pattern/words/strings: