egrep [-cinv] [-e expression] [-f filename] [expression] [filename] egrep searches the input filename (the standard input default) for lines matching a regular expression. Normally, each matching line is copied to the standard output. Take care when using the characters `$', `*', `[', `^', `|', `(', `)', `\', and space in the expression, as these characters are also meaningful to the shell. It is safest to enclose the entire expression argument in single quotes '...', or to put the expression into a file and use the `-f' option. -c Display a count of matching lines rather than displaying the lines which match. -i Ignore the case of letters in making comparisons - that is, upper and lower case are considered identical. -n Precede each line by its relative line number in the file. -v Invert the search to only display lines that do not match. -e expression Same as a simple expression argument, but useful when the expression begins with a `-'. -f filename Take the regular expression from filename. REGULAR EXPRESSIONS The following regular expressions match a single character: c An ordinary character (not one of the special characters discussed below) matches that character. \c A backslash (\) followed by any special character matches the special character itself. The special characters are: `.', `*', `[', and `\' which are always special, except when they appear within square brackets ([]). `^' which is special at the beginning of an entire regular expression, or when it immediately follows the left of a pair of square brackets ([]). `$' which is special at the end of an entire regular expression. . A regular expression that matches any character except NEWLINE. [string] A non-empty string of characters enclosed in square brackets matches any one character in that string. If, however, the first character of the string is a `^' the regular expression matches any character except NEWLINE and the remaining characters in the string. The `^' has this special meaning only if it occurs first in the string. The `-' may be used to indicate a range of consecutive ASCII characters; for example, [0-9] is equivalent to [0123456789]. The `-' loses this special meaning if it occurs first (after an initial `^', if any) or last in the string. The `]' does not terminate such a string when it is the first character within it (after an initial `^', if any); that is, []a-f] matches either `]' or one of the letters a through f inclusive. The four characters `.', `*', `[', and `\' stand for themselves within such a string of characters. The following rules may be used to construct regular expressions: Concatenation The concatenation of regular expressions matches the concatenation of the strings matched by each component of the regular expression. ^ at the beginning of an entire regular expression constrains that regular expression to match an initial segment of a line. $ at the end of an entire regular expression constrains that regular expression to match a final segment of a line. The construction example% ^entire regular expression$ constrains the entire regular expression to match the entire line. * A regular expression followed by `*' matches zero or more occurrences of the regular expression. If there is any choice, the longest leftmost string that permits a match is chosen. + A regular expression followed by `+' matches one or more occurrences of the regular expression. If there is any choice, the longest leftmost string that permits a match is chosen. ? A regular expression followed by `?' matches zero or one occurrences of the regular expression. If there is any choice, the longest leftmost string that permits a match is chosen. | Alternation: two regular expressions separated by `|' match either a match for the first or a match for the second. () A regular expression enclosed in parentheses matches a match for the regular expression. The order of precedence of operators at the same parenthesis level is `[ ]' (character classes), then `*' `+' `?' (closures), then concatenation, then `|' (alternation). However, I would strongly encourage you to use parentheses rather than relying on these precedence rules. EXAMPLES Search a file for a fixed string: example% egrep intro /usr/share/man/man3/*.3* Look for character classes: example% egrep '[1-8]([CJMSNX])' /usr/share/man/man1/*.1 Look for alternative patterns: example% egrep '(Sally|Fred) (Smith|Jones|Parker)' telephone.list