Open System Services Shell and Utilities Reference Manual (G06.29+, H06.08+, J06.03+)

User Commands (g - j) grep(1)
4. To display all lines that contain ASCII letters in parentheses or digits in
parentheses (with spaces optionally preceding and following the letters
or digits), but not letter-digit combinations in parentheses, enter:
grep -E \
’\( *([a-zA-Z]*[0-9]*) *\)’ my.txt
This command displays lines file in my.txt such as (y) or ( 783902), but
not (alpha19c).
Note that with the command grep -E, \( and \) match parentheses in the
text and ( and ) are special characters that group parts of the pattern.
With the grep command without the -E flag, the reverse is true; use (
and ) to match parentheses and \( and \) to group characters.
5. To display all lines that do not match a pattern, enter:
grep -v ’ˆ#’
This displays all lines that do not begin with a # (number sign).
6. To display the names of files that contain a pattern, enter:
grep -l -F ’rose *.list
This command searches the files in the current directory whose names
end with .list and displays the names of those files that contain at least
one line containing the string rose.
A space character is required between the -F flag and the literal string
specification.
7. To display all lines that contain uppercase characters, enter:
grep ’[[:upper:]]’ pgm.s
EXIT VALUES
The exit values of the grep command are as follows:
0 A match was found.
1 No match was found.
2 A syntax error was found or a file was inaccessible, even if matches
were found.
RELATED INFORMATION
Commands: ed(1), sed(1), sh(1).
Files: locale(4).
527188-021 Hewlett-Packard Company 431