Open System Services Shell and Utilities Reference Manual (G06.28+, H06.05+)
grep(1) OSS Shell and Utilities Reference Manual
NAME
grep - Search a file for a pattern
SYNOPSIS
grep [-E | -F][-c | -l | -q][-bhinsvwxy][-pparagraph_separator ...]
{pattern ... | -e pattern ... | -f pattern_file ...} [file ... ]
FLAGS
While most flags can be combined, some combinations result in one flag overriding another. For
example, if you specify the -n and -l flags, the output includes filenames only (as specified by the
-l flag) and thus does not include line numbers (as specified by the -n flag).
-b Precedes each line by the block number in which it was found. Use this flag to help
find disk block numbers by context.
-c Displays only a count of matching lines.
-e pattern ...
Specifies a pattern. This flag works the same as a simple pattern but is useful when the
pattern begins with a - (dash).
-E Uses extended regular expressions (EREs) to match patterns (treats each pattern as an
ERE). A null ERE matches every line.
-f pattern_file ...
Specifies a file that contains patterns. Each pattern terminates with a newline charac-
ter.
-F Uses fixed strings to match patterns (treats each pattern as a literal string instead of as
a regular expression). A null string matches every line.
-h Suppresses reporting of filenames when multiple files are processed.
-i Ignores the case of letters in locating pattern; that is, uppercase and lowercase letters
in the input are considered identical (same as the -y flag).
-l Lists the name of each file with lines matching pattern. Each filename is listed only
once; filenames are separated by newline characters.
-n Precedes each line with its relative line number in the file.
-pparagraph_separator ...
Displays the entire paragraph containing matched lines. Paragraphs are delimited by
paragraph separators specified by paragraph_separator, which is a BRE pattern. Lines
containing the paragraph separators are used only as separators; they are never
included in the output. The default paragraph separator is a blank line. No space is per-
mitted between the flag and the paragraph separator.
-q Suppresses all output except error messages. This is useful for easily determining
whether or not a pattern or string exists in a group of files. When searching several
files, it provides a performance improvement because it can quit as soon as it finds the
first match, and it requires less care by the user in choosing the set of files to supply as
arguments because it exits with a 0 (zero) exit status if it detects a match, even if the
grep command detected an access or read error on earlier file arguments.
-s Suppresses error messages about inaccessible files.
-v Displays all lines except those that match the specified pattern. This flag is useful for
filtering unwanted lines out of a file.
4−24 Hewlett-Packard Company 527188-007