grep(1)
NAME
grep − search a file for a pattern
SYNOPSIS
grep [ −bchilnsvw ] limited-regular-expression [ filename ... ]
AVAILABILITY
SUNWcsu
DESCRIPTION
grep searches files for a pattern and prints all lines that contain that pattern. grep uses limited regular expressions (expressions that have string values that use a subset of the possible alphanumeric and special characters) like those used with ed(1) to match the patterns. It uses a compact non-deterministic algorithm.
Be careful using the characters $, ∗, [, ^, │, (, ), and \ in the limited-regular-expression because they are also meaningful to the shell. It is safest to enclose the entire limited-regular-expression in single quotes ′...′.
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.
OPTIONS
−b Precede each line by the block number on which it was found. This can be useful in locating block numbers by context (first block is 0).
−c Print only a count of the lines that contain the pattern.
−h Prevents the name of the file containing the matching line from being appended to that line. Used when searching multiple files.
−i Ignore upper/lower case distinction during comparisons.
−l Print only the names of files with matching lines, separated by NEWLINE characters. Does not repeat the names of files when the pattern is found more than once.
−n Precede each line by its line number in the file (first line is 1).
−s Suppress error messages about nonexistent or unreadable files
−v Print all lines except those that contain the pattern.
−w Search for the expression as a word as if surrounded by \< and \>.
ENVIRONMENT
If any of the LC_∗ variables ( LC_CTYPE, LC_MESSAGES, LC_TIME, LC_COLLATE, LC_NUMERIC, and LC_MONETARY ) (see environ(5)) are not set in the environment, the operational behavior of grep for each corresponding locale category is determined by the value of the LANG environment variable. If LC_ALL is set, its contents are used to override both the LANG and the other LC_∗ variables. If none of the above variables is set in the environment, the "C" (U.S. style) locale determines how grep behaves.
SEE ALSO
ed(1), egrep(1), fgrep(1), sed(1), sh(1), environ(5)
DIAGNOSTICS
Exit status is 0 if any matches are found, 1 if none, 2 for syntax errors or inaccessible files (even if matches were found).
NOTES
Lines are limited to BUFSIZ characters; longer lines are truncated. BUFSIZ is defined in /usr/include/stdio.h. If there is a line with embedded nulls, grep will only match up to the first null; if it matches, it will print the entire line.
SunOS 5.1 — Last change: 26 Sep 1992