GREP(1) | User Commands | GREP(1) |
grep - search a file for a pattern
/usr/5bin/grep [-bcHhilnrRsvwz] pattern [file ...]
/usr/5bin/posix/grep [-E|-F] -e pattern_list ... [-f pattern_file] [-c|-l|-q] [-bhinrRsvwxz] [file ...]
/usr/5bin/posix/grep [-E|-F] -f pattern_file [-e pattern_list ...] [-c|-l|-q] [-bhinrRsvwxz] [file ...]
/usr/5bin/posix/grep [-E|-F]
[-c|-l|-q] [-bhinrRsvwxz] pattern_list
[file ...]
The grep command searches the lines of the specified files (or of standard input) for occurrences of the regular expression pattern. The default behavior is to print each matching line to standard output.
The /usr/5bin/grep command accepts one pattern that is treated as a simple regular expression; it uses a compact nondeterministic algorithm.
The /usr/5bin/posix/grep command uses basic regular expressions by default and accepts a newline-separated list of patterns as described for the -e option below. It uses a deterministic algorithm with moderate space requirements for most expressions; backreferences, word delimiters, and multi-character collating elements cause a nondeterministic algorithm to be used.
/usr/5bin/s42/grep and /usr/5bin/posix2001/grep are identical to /usr/5bin/posix/grep.
See the description of ed(1) for the specifications of simple and basic regular expressions.
Care should be taken when using the characters $ * [ ^ | ? ´ " ( ) and \ in the expression as they are also meaningful to the Shell. It is safest to enclose the entire expression argument in single quotes ´ ´.
Both /usr/5bin/grep and /usr/5bin/posix/grep accept the following options:
The following options are supported by /usr/5bin/posix/grep only:
The following options are supported as extensions:
ed(1), egrep(1), fgrep(1), sed(1), locale(7)
Exit status is 0 if any matches are found, 1 if none, 2 for syntax errors or inaccessible files.
If a line contains a NUL character, only matches up to this character are found (unless /usr/5bin/posix/grep is used with the -F option). The entire matching line will be printed.
The LC_COLLATE variable has currently no effect. Ranges in bracket expressions are ordered as byte values in single-byte locales and as wide character values in multibyte locales; equivalence classes match the given character only, and multi-character collating elements are not available.
The options supported by /usr/5bin/posix/grep that are not accepted by /usr/5bin/grep can easily be replaced by portable constructs: Use egrep instead of -E, fgrep instead of -F. Use egrep if you need the -e or -f option, use only one of them and that only once; if necessary, use text processing tools to generate a single expression list before. Redirect standard output to /dev/null for -q (the possible speedup with -q is never worth human time spent with porting scripts), and use the `^' and `$' meta-characters instead of -x.
8/14/05 | Heirloom Toolchest |