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
![](https://i0.wp.com/www.linuxcommands.site/wp-content/uploads/2019/05/image-69.png?fit=640%2C283&ssl=1)
You can also use the grep regex.
➜ grep -E “hello|world” test.txt
![](https://i0.wp.com/www.linuxcommands.site/wp-content/uploads/2019/05/image-70.png?fit=640%2C311&ssl=1)
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”
![](https://i2.wp.com/www.linuxcommands.site/wp-content/uploads/2019/05/image-71.png?fit=640%2C240&ssl=1)