UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 26.8 I Never Meta Character I Didn't Like Chapter 26
Regular Expressions (Pattern Matching)
Next: 26.10 Pattern Matching Quick Reference with Examples
 

26.9 Valid Metacharacters for Different UNIX Programs

Some regular expression metacharacters are valid for one program but not for another. Those that are available to a particular UNIX program are marked by a bullet (·) in Table 26.4. Quick reference descriptions of each of the characters can be found in article 26.10.

[Unfortunately, even this table doesn't give the whole story. For example, Sun has taken some of the extensions originally developed for ed, ex, and vi (such as the \< \> and \{min, max\} modifiers) and added them to other programs that use regular expressions. So don't be bashful - try things out, but just don't be surprised if every possible regular expression feature isn't supported by every program. In addition, there are many programs that recognize regular expressions, such as perl, emacs, more, dbx, expr, lex, pg, and less, that aren't covered in Daniel's table. -TOR ]

Table 26.4: Valid Metacharacters for Different Programs
SymboledexvisedawkgrepegrepAction
.·······Match any character.
*·······

Match zero or more preceding.

^·······Match beginning of line.
$·······Match end of line.
\·······

Escape character following.

[ ]·······Match one from a set.
\(\)···

Store pattern for later replay.

\{\}···

Match a range of instances.

\<\>···

Match word's beginning or end.

+··

Match one or more preceding.

?··

Match zero or one preceding.

|··

Separate choices to match.

()··

Group expressions to match.

In ed, ex, and sed, note that you specify both a search pattern (on the left) and a replacement pattern (on the right). The metacharacters in Table 26.4 are meaningful only in a search pattern. ed, ex, and sed support the additional metacharacters in Table 26.5 that are valid only in a replacement pattern.

Table 26.5: Valid Metacharacters for Replacement Patterns
SymbolexsededAction
\···Escape character following.
\n···Reuse pattern stored in \( \).
&··Reuse previous search pattern.
~·Reuse previous replacement pattern.
\u \U·Change character(s) to uppercase.
\l \L·Change character(s) to lowercase.
\E·Turn off previous \U or \L.
\e·Turn off previous \u or \l.

- DG


Previous: 26.8 I Never Meta Character I Didn't Like UNIX Power ToolsNext: 26.10 Pattern Matching Quick Reference with Examples
26.8 I Never Meta Character I Didn't Like Book Index26.10 Pattern Matching Quick Reference with Examples

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System