05 August 2008

grep and regular expressions

How to use grep with a resonably simple regexp, but which enables me to use OR? I mean, matching A OR B??? Got it... see the example:


cat /var/log/syslog | grep 'vpnc\|wlan0'


See the grep man page (type man grep at the prompt)


Basic vs Extended Regular Expressions
In basic regular expressions the meta-characters ?, +, {, |, (, and ) lose their special meaning; instead use the backslashed versions \?, \+, \{, \|, \(, and \).

Links:
http://www.amk.ca/python/howto/regex/regex.html
http://analyser.oli.tudelft.nl/regex/index.html.en