Open System Services Shell and Utilities Reference Manual (G06.27+, H06.04+)

grep(1) OSS Shell and Utilities Reference Manual
the pattern .* matches 122333444, the pattern .*3 matches 122333, and the pattern .*2
matches 122.
An RE followed by:
\{number\}
Matches exactly number occurrences of the character matched by the RE.
\{number,\}
Matches at least number occurrences of the character matched by the RE.
\{number1,number2\}
Matches any number of occurrences of the character matched by the RE from
number1 to number2, inclusive.
The values of number1 and number2 must be integers in the range 0 through
255, inclusive. Whenever a choice exists, this pattern matches as many
occurrences as possible.
Note that if number is 0 (zero), pattern matches zero occurrences of pattern;
for example:
$ echo abc | grep aX\{0\}bX\{0\}cX\{0\}
abc
$
You can combine REs into patterns that match strings containing the same sequence of
characters. For example, AB*CD matches the string ABCD and [A-Za-z]*[0-9]*
matches any string that contains any combination of ASCII alphabetic characters
(including none), followed by any combination of numerals (including none).
The character sequence \(pattern\) matches pattern and saves it into a numbered holding
space. Using this sequence, up to nine patterns can be saved on a line. Counting from
left to right on the line, the rst pattern saved is placed in the rst holding space, the
second pattern is placed in the second holding space, and so on.
The character sequence \n matches the nth saved pattern, which is placed in the nth hold-
ing space. (The value of n is a digit, 1-9.) Thus, the following pattern:
\(A\)\(B\)C\2\1
matches the string ABCBA. You can nest patterns to be saved in holding spaces.
Whether the enclosed patterns are nested or in a series, \n refers to the nth occurrence,
counting from the left, of the delimiting characters, \).
Restricting What Patterns Match
A pattern can be restricted to match from the beginning of a line, up to the end of the line, or the
entire line:
A ˆ (circumex) at the beginning of a pattern causes the pattern to match only a string
that begins in the rst character position on a line.
A $ (dollar sign) at the end of a pattern causes that pattern to match only if the last
matched character is the last character (not including the newline character) on a line.
The construction ˆpattern$ restricts the pattern to matching only an entire line.
424 Hewlett-Packard Company 527188-004