Searching for multiple words with grep


0

Assume that we have the following excerpt about paneer with three crossreferences–paneer.txt:

NA paneer
DE Paneer is a fresh cheese common in the Indian subcontinent.
XR 32853067
XR IND606876454
XR PPR204047

We would normally use grep WORD for extracting lines containing the word WORD. But how do we extract lines which contain WORD1 or WORD2?


1 Antwort

0

We can combine multiple expressions in grep:

grep -e WORD1 -e WORD2

Applied on our example, we can extract the name and description using:

grep -e '^NA ' -e '^XR ' paneer.txt