GREP comes with a rich set of options from POSIX.2 and GNU extensions.
`-c '
` --count '
|
Suppress normal output; instead print a count of matching
lines for each input file. With the ` |
`-e pattern '
` --regexp=pattern '
|
Use pattern as the pattern; useful to protect patterns
beginning with a ` |
`-f file '
` --file=file '
|
Obtain patterns from file, one per line. The empty file contains zero patterns, and therefore matches nothing. |
`-i '
` --ignore-case '
|
Ignore case distinctions in both the pattern and the input files. |
`-l '
` --files-with-matches '
|
Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning of every file will stop on the first match. |
`-n '
` --line-number '
|
Prefix each line of output with the line number within its input file. |
`-q '
` --quiet '
` --silent '
|
Quiet; suppress normal output. The scanning of every file will stop on
the first match. Also see the ` |
`-s '
` --no-messages '
|
Suppress error messages about nonexistent or unreadable files.
Portability note: unlike GNU GREP, BSD GREP does not comply
with POSIX.2, because BSD GREP lacks a ` |
`-v '
` --revert-match '
|
Invert the sense of matching, to select non-matching lines. |
`-x '
` --line-regexp '
|
Select only those matches that exactly match the whole line. |
`-A num '
` --after-context=num '
|
Print num lines of trailing context after matching lines. |
`-B num '
` --before-context=num '
|
Print num lines of leading context before matching lines. |
`-C '
` --context[=num] '
|
Print num lines (default 2) of output context. |
`-NUM '
|
Same as ` |
`-V '
` --version '
|
Print the version number of GREP to the standard output stream. This version number should be included in all bug reports. |
`--help '
|
Print a usage message briefly summarizing these command-line options and the bug-reporting address, then exit. |
`-b '
` --byte-offset '
|
Print the byte offset within the input file before each line of output.
When GREP runs on MS-DOS or MS-Windows, the printed byte offsets
depend on whether the ` |
`-d action '
` --directories=action '
|
If an input file is a directory, use action to process it.
By default, action is ` |
`-h '
` --no-filename '
|
Suppress the prefixing of filenames on output when multiple files are searched. |
`-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 of every file will stop on the first match. |
`-a '
` --text '
|
Do not suppress output lines that contain binary data. Normally, if the first few bytes of a file indicate that the file contains binary data, grep outputs only a message saying that the file matches the pattern. This option causes grep to act as if the file is a text file, even if it would otherwise be treated as binary. Warning: the result might be binary garbage printed to the terminal, which can have nasty side-effects if the terminal driver interprets some of it as commands. |
`-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. |
`-r '
` --recursive '
|
For each directory mentioned in the command line, read and process all
files in that directory, recursively. This is the same as the ` |
`-y '
|
Obsolete synonym for ` |
`-U '
` --binary '
|
Treat the file(s) as binary. By default, under MS-DOS
and MS-Windows, GREP guesses the file type by looking
at the contents of the first 32KB read from the file.
If GREP decides the file is a text file, it strips the
CR characters from the original file contents (to make
regular expressions with |
`-u '
` --unix-byte-offsets '
|
Report Unix-style byte offsets. This switch causes
GREP to report byte offsets as if the file were Unix style
text file, i.e. the byte offsets ignore the CR characters which were
stripped off. This will produce results identical to running GREP on
a Unix machine. This option has no effect unless ` |
Several additional options control which variant of the GREP matching engine is used. See Grep Programs.
GREP uses the environment variable LANG to provide internationalization support, if compiled with this feature.