Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grep match with string1 OR string2

Tags:

grep

solaris

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

like image 614
user742004 Avatar asked May 06 '11 23:05

user742004


People also ask

How do I grep a word in multiple documents?

To search multiple files with the grep command, insert the filenames you want to search, separated with a space character. The terminal prints the name of every file that contains the matching lines, and the actual lines that include the required string of characters. You can append as many filenames as needed.


1 Answers

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'
like image 79
Mikel Avatar answered Sep 27 '22 18:09

Mikel