Using other examples of regular expressions

In the previous section, we showed you how to use the grep command to search with regular expressions. You can, though, do other neat finding things tasks, as we'll discuss in this section.

To review files and spell check them:

  • cat limerick[1256].htm | spell
    In this example, we use the regular expression [1256] to find limerick1.htm, limerick2.htm, and so on. Then, we pipe the four files to spell for a quick spell check.

To find lines with specific characteristics:

1.
grep ^Nantucket limerick*
Here, we use grep to find all of the lines in the limericks that start with Nantucket, if there are any.
2.
grep Nantucket$ limerick*
Similarly, you can find the lines that end with Nantucket.
3.
 grep ^[A-Z] ...

Get Unix: Visual QuickStart Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.