Linux in a NutshellLinux in a NutshellSearch this book

9.2. Metacharacters, Listed by Linux Program

Some metacharacters are valid for one program but not for another. Those available to a given program are marked by a checkmark () in the following table. Notes are provided after the table, and full descriptions of metacharacters are in the following section.

Symbol

ed

vi

sed

gawk

grep

egrep

Action

.

Match any character (can match newline in gawk).

*

Match zero or more preceding elements.

^

Match beginning of line or string.

$

Match end of line or string.

\

Escape following character.

[ ]

Match one from a list or range.

\( \)

     

Store pattern for later replay.

\n

     

Reuse matched text stored in nth \( \).

{ }

     

   

Match a range of instances.

\{ \}

 

 

Match a range of instances.

\<

 

       

Match word's beginning.

\>

 

       

Match word's end.

+

     

Match one or more preceding elements.

?

     

Match zero or one preceding elements.

|

     

 

Separate choices to match.

( )

     

 

Group expressions to match.

On some Linux systems, grep is a link to egrep, so whenever you run grep you actually get egrep behavior.

In ed, vi, and sed, when you perform a search-and-replace (substitute) operation, the metacharacters in this table apply to the pattern you are searching for but not to the string replacing it.

In gawk, { } is specified in the POSIX standard and is supported by gawk if you run it with the -Wre-interval option.

In ed, vi, and sed, the following additional metacharacters are valid only in a replacement pattern:

Symbol

ex

sed

ed

Action

\

Escape following character.

\n

Reuse matched text stored in nth \( \).

&

 

Reuse previous search pattern.

~

   

Reuse previous replacement pattern.

\e

   

Turn off previous \L or \U.

\E

   

Turn off previous \L or \U.

\l

   

Change single following character to lowercase.

\L

   

Change following characters to lowercase until \E is encountered.

\u

   

Change single following character to uppercase.

\U

   

Change following characters to uppercase until \E is encountered.



Library Navigation Links

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