grep multiple words/patterns/strings, and/or condition, use -e or regex
May 29, 2019
Sometimes we need to use the grep command to find multiple words in one file, or to find multiple words in the same line.
1. Match multiple words in a file and the relationship between them is or.
➜ grep -e “hello” -e “world” test.txt

You can also use the grep regex.
➜ grep -E “hello|world” test.txt

More regular usage: grep regex
2. Match multiple words in one line, and the relationship between them is and
➜ grep -e “hello” test.txt| grep -e “world”
