Using regular expressions
So far, we have maintained our use of regular expressions (RE) to simple text but there is, of course, a lot more to learn from them. Although people may often think that the RE seems like comic book profanity that you may see in a Batman fight, they do have a powerful meaning.
Working with alternate spellings
To start with, let's look at some anomalies in spelling. The word color may be spelled colour or color depending upon if we were working with UK English or US English. This can give rise to issues when searching for the word color, as it may be spelled in two ways. Implementing the following command will return only the first line containing the word color and not the second line:
$ echo -e "color\ncolour" | grep color
If we need to return both spellings, then we can use an RE
operator. We will make use of the ?
operator. You should be aware that in an RE
the ?
operator is not the same as in the shell. In an RE
the ?
operator means that the previous character...