grep match with string1 OR string2

user742004 picture user742004 · May 7, 2011 · Viewed 17.2k times · Source

I want to grep 2 patterns in a file on Solaris UNIX.

That is grep 'pattern1 OR pattern2' filename.

The following command does NOT work:

grep 'pattern1\|pattern2' filename

What is wrong with this command?

NOTE: I am on Solaris

Answer

Mikel picture Mikel · May 7, 2011

What operating system are you on?

It will work with on systems with GNU grep, but on BSD, Solaris, etc., \| is not supported.

Try egrep or grep -E, e.g.

egrep 'pattern1|pattern2'