Chapter 7. Pattern Matching

A number of Linux text-processing utilities let you search for, and in some cases change, text patterns rather than fixed strings. These utilities include the editing programs ed, ex, vi, and sed; the gawk programming language; and the commands grep and egrep. Text patterns (called regular expressions in computer science literature) contain normal characters mixed with special characters (called metacharacters).

Perl’s regular expression support is so rich that it does not fit into this book; you can find a description in the O’Reilly books Mastering Regular Expressions by Jeffrey E.F. Friedl, Regular Expression Pocket Reference by Tony Stubblebine, Perl in a Nutshell by Nathan Patwardhan et al., or Perl 5 Pocket Reference by Johan Vromans. The Emacs editor also provides regular expressions similar to those shown in this chapter. See the O’Reilly books Learning GNU Emacs by Debra Cameron et al., or GNU Emacs Pocket Reference, also by Debra Cameron, for details.

This chapter presents the following topics:

  • Filenames versus patterns

  • Description of metacharacters

  • List of metacharacters available to each program

  • Examples

For more information on regular expressions, see the aforementioned O’Reilly book Mastering Regular Expressions.

Get Linux in a Nutshell, 6th Edition 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.