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?

✓ Tip


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.63.145