To use the grep command to search for metacharacters such as & ! . * ? and \, precede the metacharacter with a backslash (\). The backslash tells grep to ignore (escape) the metacharacter.
For example, the following expression matches lines that start with a period, and is useful when searching for nroff or troff formatting requests (which begin with a period).
$ grep ^\. |
Table 4–1 lists common search pattern elements you can use with grep.
Table 4–1 grep Search Pattern Elements
Character |
Matches |
---|---|
The beginning of a text line |
|
The end of a text line |
|
Any single character |
|
[...] |
Any single character in the bracketed list or range |
[^...] |
Any character not in the list or range |
Zero or more occurrences of the preceding character or regular expression |
|
.* |
Zero or more occurrences of any single character |
The escape of special meaning of next character |
Note that you can also use these search characters in vi text editor searches.