grep

Name

grep -- print lines matching a pattern

Description

The specification for "grep" is as specified in the SUS but with the following differences as listed below.

Differences

-A NUM, --after-context=NUM

Print NUM lines of trailing context after matching lines.

-a, --text

Process a binary file as if it were text; this is equivalent to the --binary-files=text option.

-B NUM, --before-context=NUM

Print NUM lines of leading context before matching lines.

-C [NUM], -NUM, --context[=NUM]

Print NUM lines (default 2) of output context.

-b, --byte-offset

Print the byte offset within the input file before each line of output.

--binary-files=TYPE

If the first few bytes of a file indicate that the file contains binary data, assume that the file is of type TYPE. By default, TYPE is binary, and grep normally outputs either a one-line message saying that a binary file matches, or no message if there is no match. If TYPE is without-match, grep assumes that a binary file does not match; this is equivalent to the -I option. If TYPE is text, grep processes a binary file as if it were text; this is equivalent to the -a option. Warning: grep --binary-files=text might output binary garbage, which can have nasty side effects if the output is a terminal and if the terminal driver interprets some of it as commands.

-c, --count

Suppress normal output; instead print a count of matching lines for each input file. With the -v, --invert-match option (see below), count non-matching lines.

-d ACTION, --directories=ACTION

If an input file is a directory, use ACTION to process it. By default, ACTION is read, which means that directories are read just as if they were ordinary files. If ACTION is skip, directories are silently skipped. If ACTION is recurse, grep reads all files under each directory, recursively; this is equivalent to the -r option.

-G, --basic-regexp

Interpret PATTERN as a basic regular expression (see below). This is the default.

-H, --with-filename

Print the filename for each match.

-h, --no-filename

Suppress the prefixing of filenames on output when multiple files are searched.

-I

Process a binary file as if it did not contain matching data; this is equivalent to the --binary-files=without-match option.

--ignore-case

Equivalent to -i

-L, --files-without-match

Suppress normal output; instead print the name of each input file from which no output would normally have been printed. The scanning will stop on the first match.

--files-with-matches

Equivalent to -l

--map

If possible, use the mmap(2) system call to read input, instead of the default read(2) system call. In some situations, --mmap yields better performance. However, --mmap can cause undefined behavior (including core dumps) if an input file shrinks while grep is operating, or if an I/O error occurs.

--line-number

Equivalent to -n

--quiet

Equivalent to -q

-r, --recursive

Read all files under each directory, recursively; this is equivalent to the -d recurse option.

--no-messages

Equivalent to -s

-V, --version

Print the version number of grep to standard error.

--invert-match

Equivalent to -v

-w, --word-regexp

Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or preceded by a non-word constituent character. Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word-constituent characters are letters, digits, and the underscore.

--line-regexp

Equivalent to -x

-Z, --null

Output a zero byte (the ASCII NUL character) instead of the character that normally follows a file name.