user5499177 user5499177 - 1 month ago 10
Linux Question

How to search multiple patterns in using grep command?

I am learning to use grep and I tried to use the following commands to find entries in

/var/log/messages
file, but I get errors:

grep "Oct 23 21:22:44" | "80" /var/log/messages


I get error for this. Than I tried the following and replaced double quotes with single quotes:

grep 'Oct 23 21:22:44' | '80' /var/log/messages


This did not work either. Why is it wrong because we can search multiple patterns using pipe!
Is it because Oct 23 21:22:44 and 80 are in different places!

80 and the date are in different orders in the file!

Answer

this syntax:

grep "Oct 23 21:22:44" | "80" /var/log/messages

is equivalent to running grep and pass output to a file called 80.

What you need is -E option to enable "extended" regular expressions, like this:

grep -E "Oct 23 21:22:44|80" /var/log/messages