- Multiple subpatterns can be provided as alternatives, separated with
\|
, for example:
$ grep 'fish\|chips\|pies' food.txt # first method
$ grep -E 'fish|chips|pies' food.txt # second method
- The previous command finds lines which match at least one of the words
- Use
\(...\)
to enforce precedence:
$ grep -i '\(cream\|fish\|birthday\) cakes' delicacies.txt
- Use square brackets to build a character class:
$ grep '[Jj]oe [Bb]loggs' staff.txt
- Any single character from the class matches; and ranges of characters can be expressed as
'a-z'