The specification for "grep" is as specified in the SUS but with the following differences as listed below.
Print NUM lines of trailing context after matching lines.
Process a binary file as if it were text; this is equivalent to the --binary-files=text option.
Print NUM lines of leading context before matching lines.
Print NUM lines (default 2) of output context.
Print the byte offset within the input file before each line of output.
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.
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.
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.
Interpret PATTERN as a basic regular expression (see below). This is the default.
Print the filename for each match.
Suppress the prefixing of filenames on output when multiple files are searched.
Process a binary file as if it did not contain matching data; this is equivalent to the --binary-files=without-match option.
Equivalent to -i
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.
Equivalent to -l
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.
Equivalent to -n
Equivalent to -q
Read all files under each directory, recursively; this is equivalent to the -d recurse option.
Equivalent to -s
Print the version number of grep to standard error.
Equivalent to -v
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.
Equivalent to -x
Output a zero byte (the ASCII NUL character) instead of the character that normally follows a file name.