I know that the | character is supposed to be used for alternation, but I just can't seem to get it to work with command line grep. The easy way I've found to do alternation is to use -e switch like so:
grep -e someregex1 -e someregex2 file.txt
Using more than one -e on the command line implies alternation.
Thursday, November 12, 2009
Simple way to do alternation with grep (command line)
Labels:
command line,
commandline,
grep,
shell
Subscribe to:
Post Comments (Atom)
2 comments:
Alternations through the vertical bar are not supported in grep's default mode. You need to either use the "-E" option (which enables extended mode) or invoke "egrep" which is exactly equivalent.
or escape it \|
e.g. grep reg_expr1\|reg_expr2
Post a Comment