Open System Services Shell and Utilities Reference Manual (G06.25+, H06.03+)
Table Of Contents
grep(1) OSS Shell and Utilities Reference Manual
-w Searches for the expression as a word (the pattern bracketed by nonalphanumeric char-
acters or by the beginning or end of the line). See the reference page for the ex com-
mand.
-x Displays lines that match the pattern exactly with no additional characters.
-y Ignores the case of letters in locating pattern; that is, uppercase and lowercase letters
in the input are considered to be identical (same as the -i flag).
DESCRIPTION
The grep command searches the specified files (the standard input file by default) for lines con-
taining characters that match the specified pattern and then write matching lines to standard out-
put.
The grep command searches for patterns that are limited regular expressions as described under
Regular Expressions (REs).
Command Usage
The grep command precedes the matched line with the name of the file containing it if you
specify more than one file (except when the -h flag is specified).
Lines are limited to 2048 bytes; longer lines are broken into multiple lines of 2048 or fewer
bytes. Paragraphs (under the -p flag) are currently limited to a length of 5000 bytes.
Running the grep command on a nontext file (for example, an .o file) produces unpredictable
results and is discouraged.
Regular Expressions (REs)
Regular expressions (REs) cannot contain newline characters, because these signal a new pat-
tern. The following REs match a single character:
character
An ordinary character (one other than one of the special pattern-matching characters)
matches itself.
. A . (dot) matches any single character except the newline character.
[string] A string enclosed in [](brackets) matches any one character in that string. In addition,
certain pattern-matching characters have special meanings within brackets:
^ If the first character of string is a ˆ (circumflex), the RE [ˆstring] matches any
character except the characters in string and the newline character. A ˆ has
this special meaning only if it occurs first in the string.
- You can use a - (dash) to indicate a range of consecutive characters. The
characters that fall within a range are determined by the current collating
sequence, which is defined by the LC_COLLATE environment variable. For
example, [a-d] is equivalent to [abcd] in the traditional ASCII collating
sequence.
A range can include a multicharacter collating element enclosed within
bracket-period delimiters ([. .]). The bracket-period delimiters in the RE syn-
tax distinguish multicharacter collating elements from a list of the individual
characters that make up the element.
A collating sequence can define equivalence classes for characters. An
equivalence class is a set of collating elements that all sort to the same pri-
mary location. They are enclosed within bracket-equal delimiters ([= =]). An
equivalence class generally is designed to deal with primary-secondary sort-
ing. For example, if e, è, and ê belong to the same equivalence class, then
4−22 Hewlett-Packard Company 527188-003