How to make vertical bar | work in grep

grep

Here's an example of a grep command line I've tried:

grep '(565172|565173|565175)' /var/log/cups/error_log

It doesn't produce any output, even though all 3 values are in the file multiple times.

I tried escaping the bars, and that improved things somewhat – the middle value was detected but not the first or last.

grep '(565172\|565173\|565175)' /var/log/cups/error_log

I also tried double escapes and went back to getting no results.

grep '(565172\\|565173\\|565175)' /var/log/cups/error_log

What am I doing wrong? Thanks.

Best Answer

The syntax you are trying to use belongs to extended regular expressions, so the answer is very simple, either use egrep or include the -E flag.

Related Question