A regular expression is a description of a set of characters. This description can be used to search through a file by looking for text that matches the regular expression. Regular expressions are analogous to shell wildcards (see section 6.6 on page [*]), but they are both more complicated and more powerful.
A regular expression is made up of text and metacharacters. A metacharacter is just a character with a special meaning. Metacharacters include the following: . * [] - \^ $.
If a regular expression contains only text (no metacharacters), it matches that text. For example, the regular expression “my regular expression” matches the text “my regular expression,” and nothing else. Regular expressions are usually case sensitive.
You can use the egrep command to display all lines in a file that contain a regular expression. Its syntax is as follows:
egrep ’regexp’ filename1 ...
The single quotation marks are not always needed, but they never hurt.
For example, to find all lines in the GPL that contain the word GNU, you type
egrep ’GNU’ /usr/doc/copyright/GPL
egrep will print the lines to standard output. If you want all lines that contain freedom followed by some indeterminate text, followed by GNU, you can do this:
egrep ’freedom.*GNU’ /usr/doc/copyright/GPL