grep

Name

grep -- print lines matching a pattern

Description

grep is as specified in the SUS but with differences as listed below.

Differences

-A NUM, --after-context=NUM

prints NUM lines of trailing context after matching lines.

-a, --text

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

-B NUM, --before-context=NUM

prints NUM lines of leading context before matching lines.

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

prints NUM lines (default 2) of output context.

-b, --byte-offset

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

--binary-files=TYPE

assumes that the file is of type TYPE if its first few bytes indicate it contains binary data. 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

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

-d ACTION, --directories=ACTION

processes the input file as a directory with ACTION. 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

interprets PATTERN as a basic regular expression. (default)

-H, --with-filename

prints the filename for each match.

-h, --no-filename

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

-I

processes 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

suppresses normal output; instead, prints 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

uses the mmap(2) system call to read input, if possible, 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

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

--no-messages

equivalent to -s.

-V, --version

prints the version number of grep to standard error.

--invert-match

equivalent to -v.

-w, --word-regexp

selects 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

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