How to grep two strings or words in file on Linux

I need to find two words or string in file. So i try

grep -w word1 file | grep -w word2
grep -w string1 file | grep -w string2

It is not working at all. Why don’t grep support searching two words? Is it even possible?

1 Like

Try:

grep -w 'word1\|word2' file

See my tutorial page for more info:

1 Like

hello.
you must type
grep -w 'string1\|string2' filename