Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

3.10. Perl as a better egrep

The grep command has an enhanced relative called egrep, which provides metacharacters for alternation, grouping, and repetition (see tables 3.8 and 3.9) that grep lacks. These enhancements allow egrep to provide services such as the following:

  • Simultaneously searching for matches with more than one pattern, through use of the alternation metacharacter (|):

    egrep 'Bob|Robert|Bobby'        # matches Bob, Robert, or Bobby
  • Applying anchoring or other contextual constraints to alternate patterns, through use of grouping parentheses:

    egrep '^(Bob|Robert|Bobby)'       # matches each at start of line
    egrep '\b(Bob|Robert|Bobby) Dobbs\b'     # matches each variation
  • Applying quantifiers such as “+” (meaning one or more) to multicharacter patterns, through use of grouping parentheses:

    egrep 'He said (Yadda)+ again'  # "Yadda", "YaddaYadda", etc.

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint