OpenWindows Advanced User's Guide

4.1.5 Searching for Metacharacters

Suppose you want to find lines in the text that have a dollar sign ($) in them. Preceding the dollar sign in the regular expression with a backslash (\) tells grep to ignore (escape) its special meaning. This is true for the other metacharacters (& ! . * ? and \ itself) as well.

For example, the expression

$ grep ^\.

matches lines starting with a period, and is especially useful when searching for nroff or troff formatting requests (which begin with a period).

The following table, Table 4-1, provides a list of the more commonly used search pattern elements you can use with grep.

Table 4-1 grep Search Pattern Elements




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 


Escapes special meaning of next character 

Note that these search characters can also be used in vi text editor searches.