start page | rating of books | rating of authors | reviews | copyrights

Unix Power ToolsUnix Power ToolsSearch this book

32.20. 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 check () in Table 32-5. Quick reference descriptions of each of the characters can be found in Section 32.21.

[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 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 32-5. Valid metacharacters for different programs

Symbol

ed

ex

vi

sed

awk

grep

egrep

Action

.

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 32-5 are meaningful only in a search pattern. ed, ex, and sed support the additional metacharacters in Table 32-6 that are valid only in a replacement pattern.

Table 32-6. Valid metacharacters for replacement patterns

Symbol

ex

sed

ed

Action

\

Escape character following.

\n

Reuse pattern stored by \( \) pair number \n.

&

 

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



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.