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 tasks, as we'll discuss in this section.

To find lines with specific characteristics:

  • grep '^Nantucket' limerick*

    Here, we use grep to find all of the lines in the limericks that start with Nantucket, if there are any.

  • grep 'Nantucket$' limerick*

    Similarly, you can find the lines that end with Nantucket.

  • grep '^[A-Z]' limerick

    Or, you can find the lines that start with a capital letter by including the [A-Z] regular expression.

  • grep '^[A-Z a-z]' limerick

    Here, you can find all the lines that start with any letter, but not a number or symbol. Fancy, huh?


  • You can also use regular expressions with awk and sed. See Making Global Changes with sed and Changing Files with awk in this chapter for details.

Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: