Open System Services Shell and Utilities Reference Manual (G06.28+, H06.05+)

fgrep(1) OSS Shell and Utilities Reference Manual
EXAMPLES
1. To search several les for a string of characters, enter:
fgrep strcpy *.c
This searches for the string strcpy in all les in the current directory with names ending in
.c.
2. To count the number of lines that match a pattern, enter:
fgrep -c { pgm.c
fgrep -c } pgm.c
This displays the number of lines in pgm.c that contain left and right braces.
If you do not put more than one { or } on a line in your C programs, and if the braces are
properly balanced, then the two numbers displayed will be the same.
3. To display all lines in a le that begin with an ASCII letter, enter:
fgrep -e ’ˆ[a-zA-Z] pgm.s
Note that because the fgrep command searches only for xed strings and does not inter-
pret pattern-matching characters, the following command searches only for the literal
string ˆ[a-zA-Z] in le pgm.s:
fgrep ’ˆ[a-zA-Z] pgm.s
4. To display all lines that do not match a pattern, enter:
fgrep -v ’ˆ#
This displays all lines that do not begin with a # (number sign).
5. To display the names of les that contain a pattern, enter:
fgrep -l rose *.list
This searches the les in the current directory whose names end with .list and displays the
names of those les that contain at least one line containing the string rose.
6. To display all lines that contain uppercase characters, enter:
fgrep [[:upper:]]pgm.s
EXIT VALUES
The fgrep command returns the following exit values:
0 (zero) A match was found.
1 No match was found.
2 A syntax error occurred or a le was inaccessible, even if matches were found.
RELATED INFORMATION
Commands: ed(1), egrep(1), grep(1), sed(1), sh(1).
Files: locale(4).
3132 Hewlett-Packard Company 527188-007