home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX in a Nutshell: System V Edition

UNIX in a Nutshell: System V EditionSearch this book
Previous: 6.2 Metacharacters, Listed by UNIX Program Chapter 6
Pattern Matching
Next: 6.4 Examples of Searching
 

6.3 Metacharacters

The characters below have special meaning only in search patterns:

. Match any single character except newline.
* Match any number (or none) of the single character that immediately precedes it. The preceding character can also be a regular expression. E.g., since . (dot) means any character, .* means "match any number of any character."
^ Match the following regular expression at the beginning of the line.
$ Match the preceding regular expression at the end of the line.
[ ] Match any one of the enclosed characters.
A hyphen ( - ) indicates a range of consecutive characters. A circumflex ( ^ ) as the first character in the brackets reverses the sense: it matches any one character not in the list. A hyphen or close bracket ( ] ) as the first character is treated as a member of the list. All other metacharacters are treated as members of the list.
\{ n , m \} Match a range of occurrences of the single character that immediately precedes it. The preceding character can also be a regular expression. \{ n \} matches exactly n occurrences, \{ n \} matches at least n occurrences, and \{ n , m \} matches any number of occurrences between n and m . n and m must be between 0 and 256, inclusive.
\ Turn off the special meaning of the character that follows.
\( \) Save the pattern enclosed between \( and \) into a special holding space. Up to nine patterns can be saved on a single line. They can be "replayed" in substitutions by the escape sequences \1 to \9.
\< \> Match characters at beginning (\<) or end (\>) of a word.
+ Match one or more instances of preceding regular expression.
? Match zero or one instances of preceding regular expression.
| Match the regular expression specified before or after.
( ) Apply a match to the enclosed group of regular expressions.

The characters below have special meaning only in replacement patterns.

\ Turn off the special meaning of the character that follows.
\ n Restore the n th pattern previously saved by \( and \). n is a number from 1 t 9, with 1 starting on the left.
& Reuse the search pattern as part of the replacement pattern.
~ Reuse the previous replacement pattern in the current replacement pattern.
\u Convert first character of replacement pattern to uppercase.
\U Convert replacement pattern to uppercase.
\l Convert first character of replacement pattern to lowercase.
\L Convert replacement pattern to lowercase.


Previous: 6.2 Metacharacters, Listed by UNIX Program UNIX in a Nutshell: System V Edition Next: 6.4 Examples of Searching
6.2 Metacharacters, Listed by UNIX Program Book Index 6.4 Examples of Searching

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