Metacharacters, Listed by Linux Program

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

Symbol ed vi sed awk grep egrep Action
. Screenshot Screenshot Screenshot Screenshot Screenshot Screenshot Match any character (can match newline in gawk).
* Screenshot Screenshot Screenshot Screenshot Screenshot Screenshot Match zero or more preceding.
^ Screenshot Screenshot Screenshot Screenshot Screenshot Screenshot Match beginning of line or string.
$ Screenshot Screenshot Screenshot Screenshot Screenshot Screenshot Match end of line or string.
\ Screenshot Screenshot Screenshot Screenshot Screenshot Screenshot Escape character following.
[] Screenshot Screenshot Screenshot Screenshot Screenshot Screenshot Match one from a list or range.
\(\) Screenshot Screenshot Screenshot Store pattern for later replay.
\n Screenshot Screenshot Screenshot Reuse matched text stored in nth \( \).
{} Screenshot Match a range of instances.
\{\} Screenshot Screenshot Screenshot Screenshot Match a range of instances.
\<\> Screenshot Match word's beginning or end.
+ Screenshot Screenshot Screenshot Match one or more preceding.
? Screenshot Screenshot Screenshot Match zero or one preceding.
| Screenshot Screenshot Separate choices to match.
() Screenshot Screenshot 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 awk, {} 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
\ Screenshot Screenshot Screenshot Escape character following.
\n Screenshot Screenshot Screenshot Reuse matched text stored in nth \( \).
& Screenshot Screenshot Reuse previous search pattern.
~ Screenshot Reuse previous replacement pattern.
\e Screenshot Turn off previous L or U.
\E Screenshot Turn off previous /L or /U.
\l Screenshot Change single following character to lowercase.
\L Screenshot Change following characters to lowercase until /E encountered.
\u Screenshot Change single following character to uppercase.
\U Screenshot Change following characters to uppercase until E encountered.