command is yet another version of
one that extends
the syntax of regular expressions (
A plus sign (
) following a regular expression matches one or more
occurrences of the regular expression; a question mark (
matches zero or one occurrences.
In addition, regular expressions can be nested within parentheses:
egrep "Lab(oratorie)?s" name.list
AT&T Bell Laboratories
AT&T Bell Labs
Symtel Labs of Chicago
Parentheses surround a second regular expression and
The nesting helps to eliminate unwanted matches; for instance, the
would not be matched.
Another special feature of
is the vertical bar (
serves as an
operator between two expressions.
Lines matching either expression are printed, as in
the next example:
egrep "stdscr|curscr" ch03
into the stdscr, a character array.
When stdscr is refreshed, the
stdscr is refreshed.
initscr() creates two windows: stdscr
Remember to put the expression inside quotation marks to protect the
vertical bar from being interpreted by the shell as a pipe symbol.
Look at the next example:
egrep "Alcuin (User|Programmer)('s)? Guide" docguide
Alcuin Progammer's Guide is a thorough
refer to the Alcuin User Guide
Alcuin User's Guide introduces new users to
You can see the flexibility that
's syntax can give you,
and matching them whether or not they had
has another example and explanation of
can read search patterns from a file using
utility makes a file full of complicated expressions for matching dates.
UNIX Text Processing
, Hayden Books, 1987, Chapter 11