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

User Commands (g - j) grep(1)
-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 ag).
DESCRIPTION
The grep command searches the specied les (the standard input le by default) for lines con-
taining characters that match the specied 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 le containing it if you
specify more than one le (except when the -h ag is specied).
Lines are limited to 2048 bytes; longer lines are broken into multiple lines of 2048 or fewer
bytes. Paragraphs (under the -p ag) are currently limited to a length of 5000 bytes.
Running the grep command on a nontext le (for example, an .o le) 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 rst character of string is a ˆ (circumex), the RE [ˆstring] matches any
character except the characters in string and the newline character. A ˆ has
this special meaning only if it occurs rst 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 dened 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 dene 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
527188-007 Hewlett-Packard Company 425