1 min read

Find more than one word

egrep can be quite useful when sometimes one needs to extract more than one word within a piece of text.

Working example:

Here we have a txt file that has three lines of text:

cat example.txt
## Apple
## Orange
## Banana

To find the text “Apple”:

cat example.txt | egrep "Apple"
## Apple

To find both “Apple” and “Banana”, note that a pipe symbol is added between the two words without spacing:

cat example.txt | egrep "Apple|Banana"
## Apple
## Banana