/usr/xpg4/bin/grep [ -E | -F ]
[ -c | -l | -q ] [ -bhinsvwx ] -e pattern_list... [ -f pattern_file ] ... [file...]
/usr/xpg4/bin/grep [ -E | -F ] [ -c | -l | -q ] [ -bhinsvwx ] [ -e pattern_list...
] -f pattern_file ... [file...]
/usr/xpg4/bin/grep [ -E | -F ] [ -c | -l | -q ] [ -bhinsvwx ] pattern [ file...]
Be careful using the characters $, *, [, ^, |, (, ), and \ in the pattern_list because they are also meaningful to the shell. It is safest to enclose the entire pattern_list in single quotes fm...fm.
If no files are specified, grep assumes standard input. Normally, each line found is copied to standard output. The file name is printed before each line found if there is more than one input file.
Each pattern will be interpreted as a full regular expression as described on the regex(5) manual page, except for \( and \), and including:
.- A full regular expression followed by + that matches one or more occurrences of the full regular expression.
.- A full regular expression followed by ? that matches 0 or 1 occurrences of the full regular expression.
.- Full regular expressions separated by | or by a new-line that match strings that are matched by any of the expressions.
.- A full regular expression that may be enclosed in parentheses () for grouping.
The -e pattern_list option has the same effect as the pattern_list operand, but is useful when pattern_list begins with the hyphen delimiter. It is also useful when it is more convenient to provide multiple patterns as separate arguments.
Multiple -e and -f options are accepted and grep will use all of the patterns it is given while matching input text lines. (Note that the order of evaluation is not specified. If an implementation finds a null string as a pattern, it is allowed to use that pattern first, matching every line, and effectively ignore any other patterns.)
The -q option provides a means of 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 requires less care by the user
in choosing the set of files to supply as arguments (because it will exit
zero if it finds a match even if grep detected an access or read error
on earlier file operands).
To find all uses of the word ‘Posix’ (in any case) in the file text.mm, and write with line numbers:
example% /usr/bin/grep -i -n posix text.mm
To find all empty lines in the standard input:
example% /usr/bin/grep ^$
example% /usr/bin/grep -v .
Both of the following commands print all lines containing strings abc or def or both:
example% /usr/xpg4/bin/grep -E ’abc
def’example% /usr/xpg4/bin/grep -F ’abc
def’
Both of the following commands print all lines matching exactly abc or def:
example% /usr/xpg4/bin/grep -E ’^abc$
^def$’example% /usr/xpg4/bin/grep -F -x ’abc
def’