The first of the extended regular expression features we will discuss is called alternation, which is the facility that allows a match to occur from among a set of expressions. Just as a bracket expression allows a single character to match from a set of specified characters, alternation allows matches from a set of strings or other regular expressions.
To demonstrate, we’ll use
grep in conjunction with
echo. First, let’s try a plain old string match:
echo "AAA" | grep AAAAAA [me@linuxbox ˜]$
echo "BBB" | grep AAA[me@linuxbox ˜]$
A pretty straightforward example, in which we pipe the output of
grep and see the results. When a match occurs, we see it printed out; when no match occurs, we see no results.