
700
|
Chapter 7: Pattern Matching
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
Metacharacters, Listed by Program
Some metacharacters are valid for one program but not for another. Those that
are available are marked by a bullet (•) in the following table. Items marked with a
“P” are specified by POSIX. Full descriptions were provided in the previous
section.
Note that in ed, ex, vi, and sed, you specify both a search pattern (on the left) and
a replacement pattern (on the right). The metacharacters listed above are mean-
ingful only in a search pattern.
\u Convert first character of replacement pattern to uppercase.
\U Convert entire replacement pattern to uppercase.
\l Convert first character of replacement pattern to lowercase.
\L Convert entire replacement pattern to lowercase.
\e Turn off previous \u or \l.
\E Turn off previous \U or \L.
Symbol ed ex vi sed awk grep egrep Action
. •••••••Match any character.
* •••••••Match zero or more
preceding characters.
^ •••••••Match beginning of line/
string.
$ •••••••Match end of line/string.
\ •••••••Escape following
character.
[ ] •••••••Match one from a set.
\( \) • • • • • Store pattern for later
replay.
a
a
Stored subpatterns can be “replayed” during matching. See the following table.
\n • • • • • Replay subpattern in
match.
{ } • P • P Match a range of
instances.
\{ \} • • • Match a range of
instances. ...