Open System Services Shell and Utilities Reference Manual (G06.29+, H06.08+, J06.03+)
User Commands (d - f) egrep(1)
• The construction ˆpattern$ restricts the pattern to matching only an entire line.
EXAMPLES
1. To display all lines in a file that begin with an ASCII letter, enter:
egrep ’ˆ[a-zA-Z]’ pgm.s
2. 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 combi-
nations in parentheses, enter:
egrep \
’\( *([a-zA-Z]*⏐⏐[0-9]*) *\)’ my.txt
This command displays lines in my.txt such as (y) or ( 783902), but not (alpha19c).
3. To display all lines that do not match a pattern, enter:
egrep -v ’ˆ#’
This displays all lines that do not begin with a # (number sign).
4. To display all lines that contain uppercase characters, enter:
w
egrep ’[[:upper:]]’ pgm.s
EXIT VALUES
The egrep command returns the following exit values:
0 (zero) A match was found.
1 No match was found.
2 A syntax error occurred or a file was inaccessible, even if matches were found.
RELATED INFORMATION
Commands: ed(1), ex(1), grep(1), sed(1), sh(1).
Files: locale(4).
STANDARDS CONFORMANCE
This command conforms to the XPG4 Version 2 specification.
The following features are HP extensions to the XPG4 Version 2 specification:
• The -b, -h, -q, and -x flags are supported.
527188-021 Hewlett-Packard Company 3−55