Archive for January 5th, 2009

Why grep ‘foo|bar’ file doesn’t work?

Monday, January 5th, 2009

The bar | has no special meaning in BRE (basic regular expressions). Use extended regular expressions (ERE) such as:

grep -E 'foo|bar' file


egrep 'foo|bar' file

In GNU grep, you can also force the spcial meaning of | by escaping it. E.g.,

grep 'foo\|bar' file