Blame doc/grep.in.1.man-fix-gs

Packit cb4c47
.\" GNU grep man page
Packit cb4c47
.if !\n(.g \{\
Packit cb4c47
.	if !\w|\*(lq| \{\
Packit cb4c47
.		ds lq ``
Packit cb4c47
.		if \w'\(lq' .ds lq "\(lq
Packit cb4c47
.	\}
Packit cb4c47
.	if !\w|\*(rq| \{\
Packit cb4c47
.		ds rq ''
Packit cb4c47
.		if \w'\(rq' .ds rq "\(rq
Packit cb4c47
.	\}
Packit cb4c47
.\}
Packit cb4c47
.
Packit cb4c47
.ie \n[.g] .mso www.tmac
Packit cb4c47
.el \{\
Packit cb4c47
. de MTO
Packit cb4c47
\\$2 \(laemail: \\$1 \(ra\\$3
Packit cb4c47
..
Packit cb4c47
. de URL
Packit cb4c47
\\$2 \(laURL: \\$1 \(ra\\$3
Packit cb4c47
..
Packit cb4c47
.\}
Packit cb4c47
.
Packit cb4c47
.TH GREP 1 \*(Dt "GNU grep @VERSION@" "User Commands"
Packit cb4c47
.hy 0
Packit cb4c47
.
Packit cb4c47
.SH NAME
Packit cb4c47
grep, egrep, fgrep \- print lines matching a pattern
Packit cb4c47
.
Packit cb4c47
.SH SYNOPSIS
Packit cb4c47
.B grep
Packit cb4c47
.RI [ OPTIONS ]
Packit cb4c47
.I PATTERN
Packit cb4c47
.RI [ FILE .\|.\|.]
Packit cb4c47
.br
Packit cb4c47
.B grep
Packit cb4c47
.RI [ OPTIONS ]
Packit cb4c47
.B \-e
Packit cb4c47
.I PATTERN
Packit cb4c47
\&.\|.\|.\&
Packit cb4c47
.RI [ FILE .\|.\|.]
Packit cb4c47
.br
Packit cb4c47
.B grep
Packit cb4c47
.RI [ OPTIONS ]
Packit cb4c47
.B \-f
Packit cb4c47
.I FILE
Packit cb4c47
\&.\|.\|.\&
Packit cb4c47
.RI [ FILE .\|.\|.]
Packit cb4c47
.
Packit cb4c47
.SH DESCRIPTION
Packit cb4c47
.B grep
Packit cb4c47
searches for
Packit cb4c47
.I PATTERN
Packit cb4c47
in each
Packit cb4c47
.IR FILE .
Packit cb4c47
A
Packit cb4c47
.I FILE
Packit cb4c47
of
Packit cb4c47
.RB "\*(lq" \- "\*(rq"
Packit cb4c47
stands for standard input.
Packit cb4c47
If no
Packit cb4c47
.I FILE
Packit cb4c47
is given, recursive searches examine the working directory,
Packit cb4c47
and nonrecursive searches read standard input.
Packit cb4c47
By default,
Packit cb4c47
.B grep
Packit cb4c47
prints the matching lines.
Packit cb4c47
.PP
Packit cb4c47
In addition, the variant programs
Packit cb4c47
.B egrep
Packit cb4c47
and
Packit cb4c47
.B fgrep
Packit cb4c47
are the same as
Packit cb4c47
.B "grep\ \-E"
Packit cb4c47
and
Packit cb4c47
.BR "grep\ \-F" ,
Packit cb4c47
respectively.
Packit cb4c47
These variants are deprecated, but are provided for backward compatibility.
Packit cb4c47
.
Packit cb4c47
.SH OPTIONS
Packit cb4c47
.SS "Generic Program Information"
Packit cb4c47
.TP
Packit cb4c47
.B \-\^\-help
Packit cb4c47
Output a usage message and exit.
Packit cb4c47
.TP
Packit cb4c47
.BR \-V ", " \-\^\-version
Packit cb4c47
Output the version number of
Packit cb4c47
.B grep
Packit cb4c47
and exit.
Packit cb4c47
.SS "Matcher Selection"
Packit cb4c47
.TP
Packit cb4c47
.BR \-E ", " \-\^\-extended\-regexp
Packit cb4c47
Interpret
Packit cb4c47
.I PATTERN
Packit cb4c47
as an extended regular expression (ERE, see below).
Packit cb4c47
.TP
Packit cb4c47
.BR \-F ", " \-\^\-fixed\-strings
Packit cb4c47
Interpret
Packit cb4c47
.I PATTERN
Packit cb4c47
as a list of fixed strings (instead of regular expressions),
Packit cb4c47
separated by newlines,
Packit cb4c47
any of which is to be matched.
Packit cb4c47
.TP
Packit cb4c47
.BR \-G ", " \-\^\-basic\-regexp
Packit cb4c47
Interpret
Packit cb4c47
.I PATTERN
Packit cb4c47
as a basic regular expression (BRE, see below).
Packit cb4c47
This is the default.
Packit cb4c47
.TP
Packit cb4c47
.BR \-P ", " \-\^\-perl\-regexp
Packit cb4c47
Interpret the pattern as a Perl-compatible regular expression (PCRE).
Packit cb4c47
This is experimental and
Packit cb4c47
.B "grep \-P"
Packit cb4c47
may warn of unimplemented features.
Packit cb4c47
.SS "Matching Control"
Packit cb4c47
.TP
Packit cb4c47
.BI \-e " PATTERN" "\fR,\fP \-\^\-regexp=" PATTERN
Packit cb4c47
Use
Packit cb4c47
.I PATTERN
Packit cb4c47
as the pattern.
Packit cb4c47
If this option is used multiple times or is combined with the
Packit cb4c47
.B \-f
Packit cb4c47
.RB ( \-\-file )
Packit cb4c47
option, search for all patterns given.
Packit cb4c47
This option can be used to protect a pattern beginning with \*(lq\-\*(rq.
Packit cb4c47
.TP
Packit cb4c47
.BI \-f " FILE" "\fR,\fP \-\^\-file=" FILE
Packit cb4c47
Obtain patterns from
Packit cb4c47
.IR FILE ,
Packit cb4c47
one per line.
Packit cb4c47
If this option is used multiple times or is combined with the
Packit cb4c47
.B \-e
Packit cb4c47
.RB ( \-\-regexp )
Packit cb4c47
option, search for all patterns given.
Packit cb4c47
The empty file contains zero patterns, and therefore matches nothing.
Packit cb4c47
.TP
Packit cb4c47
.BR \-i ", " \-\^\-ignore\-case
Packit cb4c47
Ignore case distinctions, so that characters that differ only in case
Packit cb4c47
match each other.
Packit cb4c47
.TP
Packit cb4c47
.BR \-v ", " \-\^\-invert\-match
Packit cb4c47
Invert the sense of matching, to select non-matching lines.
Packit cb4c47
.TP
Packit cb4c47
.BR \-w ", " \-\^\-word\-regexp
Packit cb4c47
Select only those lines containing matches that form whole words.
Packit cb4c47
The test is that the matching substring must either be at the
Packit cb4c47
beginning of the line, or preceded by a non-word constituent
Packit cb4c47
character.
Packit cb4c47
Similarly, it must be either at the end of the line
Packit cb4c47
or followed by a non-word constituent character.
Packit cb4c47
Word-constituent characters are letters, digits, and the underscore.
Packit cb4c47
This option has no effect if
Packit cb4c47
.B \-x
Packit cb4c47
is also specified.
Packit cb4c47
.TP
Packit cb4c47
.BR \-x ", " \-\^\-line\-regexp
Packit cb4c47
Select only those matches that exactly match the whole line.
Packit cb4c47
For a regular expression pattern, this is like parenthesizing the
Packit cb4c47
pattern and then surrounding it with
Packit cb4c47
.B ^
Packit cb4c47
and
Packit cb4c47
.BR $ .
Packit cb4c47
.TP
Packit cb4c47
.B \-y
Packit cb4c47
Obsolete synonym for
Packit cb4c47
.BR \-i .
Packit cb4c47
.SS "General Output Control"
Packit cb4c47
.TP
Packit cb4c47
.BR \-c ", " \-\^\-count
Packit cb4c47
Suppress normal output; instead print a count of
Packit cb4c47
matching lines for each input file.
Packit cb4c47
With the
Packit cb4c47
.BR \-v ", " \-\^\-invert\-match
Packit cb4c47
option (see below), count non-matching lines.
Packit cb4c47
.TP
Packit cb4c47
.BR \-\^\-color [ =\fIWHEN\fP "], " \-\^\-colour [ =\fIWHEN\fP ]
Packit cb4c47
Surround the matched (non-empty) strings, matching lines, context lines,
Packit cb4c47
file names, line numbers, byte offsets, and separators (for fields and
Packit cb4c47
groups of context lines) with escape sequences to display them in color
Packit cb4c47
on the terminal.
Packit cb4c47
The colors are defined by the environment variable
Packit cb4c47
.BR GREP_COLORS .
Packit cb4c47
The deprecated environment variable
Packit cb4c47
.B GREP_COLOR
Packit cb4c47
is still supported, but its setting does not have priority.
Packit cb4c47
.I WHEN
Packit cb4c47
is
Packit cb4c47
.BR never ", " always ", or " auto .
Packit cb4c47
.TP
Packit cb4c47
.BR \-L ", " \-\^\-files\-without\-match
Packit cb4c47
Suppress normal output; instead print the name
Packit cb4c47
of each input file from which no output would
Packit cb4c47
normally have been printed.
Packit cb4c47
The scanning will stop on the first match.
Packit cb4c47
.TP
Packit cb4c47
.BR \-l ", " \-\^\-files\-with\-matches
Packit cb4c47
Suppress normal output; instead print
Packit cb4c47
the name of each input file from which output
Packit cb4c47
would normally have been printed.
Packit cb4c47
The scanning will stop on the first match.
Packit cb4c47
.TP
Packit cb4c47
.BI \-m " NUM" "\fR,\fP \-\^\-max\-count=" NUM
Packit cb4c47
Stop reading a file after
Packit cb4c47
.I NUM
Packit cb4c47
matching lines.
Packit cb4c47
If the input is standard input from a regular file,
Packit cb4c47
and
Packit cb4c47
.I NUM
Packit cb4c47
matching lines are output,
Packit cb4c47
.B grep
Packit cb4c47
ensures that the standard input is positioned to just after the last
Packit cb4c47
matching line before exiting, regardless of the presence of trailing
Packit cb4c47
context lines.
Packit cb4c47
This enables a calling process to resume a search.
Packit cb4c47
When
Packit cb4c47
.B grep
Packit cb4c47
stops after
Packit cb4c47
.I NUM
Packit cb4c47
matching lines, it outputs any trailing context lines.
Packit cb4c47
When the
Packit cb4c47
.B \-c
Packit cb4c47
or
Packit cb4c47
.B \-\^\-count
Packit cb4c47
option is also used,
Packit cb4c47
.B grep
Packit cb4c47
does not output a count greater than
Packit cb4c47
.IR NUM .
Packit cb4c47
When the
Packit cb4c47
.B \-v
Packit cb4c47
or
Packit cb4c47
.B \-\^\-invert\-match
Packit cb4c47
option is also used,
Packit cb4c47
.B grep
Packit cb4c47
stops after outputting
Packit cb4c47
.I NUM
Packit cb4c47
non-matching lines.
Packit cb4c47
.TP
Packit cb4c47
.BR \-o ", " \-\^\-only\-matching
Packit cb4c47
Print only the matched (non-empty) parts of a matching line,
Packit cb4c47
with each such part on a separate output line.
Packit cb4c47
.TP
Packit cb4c47
.BR \-q ", " \-\^\-quiet ", " \-\^\-silent
Packit cb4c47
Quiet; do not write anything to standard output.
Packit cb4c47
Exit immediately with zero status if any match is found,
Packit cb4c47
even if an error was detected.
Packit cb4c47
Also see the
Packit cb4c47
.B \-s
Packit cb4c47
or
Packit cb4c47
.B \-\^\-no\-messages
Packit cb4c47
option.
Packit cb4c47
.TP
Packit cb4c47
.BR \-s ", " \-\^\-no\-messages
Packit cb4c47
Suppress error messages about nonexistent or unreadable files.
Packit cb4c47
.SS "Output Line Prefix Control"
Packit cb4c47
.TP
Packit cb4c47
.BR \-b ", " \-\^\-byte\-offset
Packit cb4c47
Print the 0-based byte offset within the input file
Packit cb4c47
before each line of output.
Packit cb4c47
If
Packit cb4c47
.B \-o
Packit cb4c47
.RB ( \-\^\-only\-matching )
Packit cb4c47
is specified,
Packit cb4c47
print the offset of the matching part itself.
Packit cb4c47
.TP
Packit cb4c47
.BR \-H ", " \-\^\-with\-filename
Packit cb4c47
Print the file name for each match.
Packit cb4c47
This is the default when there is more than one file to search.
Packit cb4c47
.TP
Packit cb4c47
.BR \-h ", " \-\^\-no\-filename
Packit cb4c47
Suppress the prefixing of file names on output.
Packit cb4c47
This is the default when there is only one file
Packit cb4c47
(or only standard input) to search.
Packit cb4c47
.TP
Packit cb4c47
.BI \-\^\-label= LABEL
Packit cb4c47
Display input actually coming from standard input as input coming from file
Packit cb4c47
.IR LABEL .
Packit cb4c47
This is especially useful when implementing tools like
Packit cb4c47
.BR zgrep ,
Packit cb4c47
e.g.,
Packit cb4c47
.BR "gzip -cd foo.gz | grep --label=foo -H something" .
Packit cb4c47
See also the
Packit cb4c47
.B \-H
Packit cb4c47
option.
Packit cb4c47
.TP
Packit cb4c47
.BR \-n ", " \-\^\-line\-number
Packit cb4c47
Prefix each line of output with the 1-based line number
Packit cb4c47
within its input file.
Packit cb4c47
.TP
Packit cb4c47
.BR \-T ", " \-\^\-initial\-tab
Packit cb4c47
Make sure that the first character of actual line content lies on a
Packit cb4c47
tab stop, so that the alignment of tabs looks normal.
Packit cb4c47
This is useful with options that prefix their output to the actual content:
Packit cb4c47
.BR \-H , \-n ,
Packit cb4c47
and
Packit cb4c47
.BR \-b .
Packit cb4c47
In order to improve the probability that lines
Packit cb4c47
from a single file will all start at the same column,
Packit cb4c47
this also causes the line number and byte offset (if present)
Packit cb4c47
to be printed in a minimum size field width.
Packit cb4c47
.TP
Packit cb4c47
.BR \-u ", " \-\^\-unix\-byte\-offsets
Packit cb4c47
Report Unix-style byte offsets.
Packit cb4c47
This switch causes
Packit cb4c47
.B grep
Packit cb4c47
to report byte offsets as if the file were a Unix-style text file,
Packit cb4c47
i.e., with CR characters stripped off.
Packit cb4c47
This will produce results identical to running
Packit cb4c47
.B grep
Packit cb4c47
on a Unix machine.
Packit cb4c47
This option has no effect unless
Packit cb4c47
.B \-b
Packit cb4c47
option is also used;
Packit cb4c47
it has no effect on platforms other than MS-DOS and MS-Windows.
Packit cb4c47
.TP
Packit cb4c47
.BR \-Z ", " \-\^\-null
Packit cb4c47
Output a zero byte (the ASCII
Packit cb4c47
.B NUL
Packit cb4c47
character) instead of the character that normally follows a file name.
Packit cb4c47
For example,
Packit cb4c47
.B "grep \-lZ"
Packit cb4c47
outputs a zero byte after each file name instead of the usual newline.
Packit cb4c47
This option makes the output unambiguous, even in the presence of file
Packit cb4c47
names containing unusual characters like newlines.
Packit cb4c47
This option can be used with commands like
Packit cb4c47
.BR "find \-print0" ,
Packit cb4c47
.BR "perl \-0" ,
Packit cb4c47
.BR "sort \-z" ,
Packit cb4c47
and
Packit cb4c47
.B "xargs \-0"
Packit cb4c47
to process arbitrary file names,
Packit cb4c47
even those that contain newline characters.
Packit cb4c47
.SS "Context Line Control"
Packit cb4c47
.TP
Packit cb4c47
.BI \-A " NUM" "\fR,\fP \-\^\-after\-context=" NUM
Packit cb4c47
Print
Packit cb4c47
.I NUM
Packit cb4c47
lines of trailing context after matching lines.
Packit cb4c47
Places a line containing a group separator
Packit cb4c47
.RB ( \-\^\- )
Packit cb4c47
between contiguous groups of matches.
Packit cb4c47
With the
Packit cb4c47
.B \-o
Packit cb4c47
or
Packit cb4c47
.B \-\^\-only\-matching
Packit cb4c47
option, this has no effect and a warning is given.
Packit cb4c47
.TP
Packit cb4c47
.BI \-B " NUM" "\fR,\fP \-\^\-before\-context=" NUM
Packit cb4c47
Print
Packit cb4c47
.I NUM
Packit cb4c47
lines of leading context before matching lines.
Packit cb4c47
Places a line containing a group separator
Packit cb4c47
.RB ( \-\^\- )
Packit cb4c47
between contiguous groups of matches.
Packit cb4c47
With the
Packit cb4c47
.B \-o
Packit cb4c47
or
Packit cb4c47
.B \-\^\-only\-matching
Packit cb4c47
option, this has no effect and a warning is given.
Packit cb4c47
.TP
Packit cb4c47
.BI \-C " NUM" "\fR,\fP \-" NUM "\fR,\fP \-\^\-context=" NUM
Packit cb4c47
Print
Packit cb4c47
.I NUM
Packit cb4c47
lines of output context.
Packit cb4c47
Places a line containing a group separator
Packit cb4c47
.RB ( \-\^\- )
Packit cb4c47
between contiguous groups of matches.
Packit cb4c47
With the
Packit cb4c47
.B \-o
Packit cb4c47
or
Packit cb4c47
.B \-\^\-only\-matching
Packit cb4c47
option, this has no effect and a warning is given.
Packit cb4c47
.SS "File and Directory Selection"
Packit cb4c47
.TP
Packit cb4c47
.BR \-a ", " \-\^\-text
Packit cb4c47
Process a binary file as if it were text; this is equivalent to the
Packit cb4c47
.B \-\^\-binary\-files=text
Packit cb4c47
option.
Packit cb4c47
.TP
Packit cb4c47
.BI \-\^\-binary\-files= TYPE
Packit cb4c47
If a file's data or metadata
Packit cb4c47
indicate that the file contains binary data,
Packit cb4c47
assume that the file is of type
Packit cb4c47
.IR TYPE .
Packit cb4c47
Non-text bytes indicate binary data; these are either output bytes that are
Packit cb4c47
improperly encoded for the current locale, or null input bytes when the
Packit cb4c47
.B \-z
Packit cb4c47
option is not given.
Packit cb4c47
.IP
Packit cb4c47
By default,
Packit cb4c47
.I TYPE
Packit cb4c47
is
Packit cb4c47
.BR binary ,
Packit cb4c47
and when
Packit cb4c47
.B grep
Packit cb4c47
discovers that a file is binary it suppresses any further output, and
Packit cb4c47
instead outputs either a one-line message saying that a binary file
Packit cb4c47
matches, or no message if there is no match.
Packit cb4c47
.IP
Packit cb4c47
If
Packit cb4c47
.I TYPE
Packit cb4c47
is
Packit cb4c47
.BR without-match ,
Packit cb4c47
when
Packit cb4c47
.B grep
Packit cb4c47
discovers that a file is binary it assumes that the rest of the file
Packit cb4c47
does not match; this is equivalent to the
Packit cb4c47
.B \-I
Packit cb4c47
option.
Packit cb4c47
.IP
Packit cb4c47
If
Packit cb4c47
.I TYPE
Packit cb4c47
is
Packit cb4c47
.BR text ,
Packit cb4c47
.B grep
Packit cb4c47
processes a binary file as if it were text; this is equivalent to the
Packit cb4c47
.B \-a
Packit cb4c47
option.
Packit cb4c47
.IP
Packit cb4c47
When
Packit cb4c47
.I type
Packit cb4c47
is
Packit cb4c47
.BR binary ,
Packit cb4c47
.B grep
Packit cb4c47
may treat non-text bytes as line terminators even without the
Packit cb4c47
.B \-z
Packit cb4c47
option.  This means choosing
Packit cb4c47
.B binary
Packit cb4c47
versus
Packit cb4c47
.B text
Packit cb4c47
can affect whether a pattern matches a file.  For
Packit cb4c47
example, when
Packit cb4c47
.I type
Packit cb4c47
is
Packit cb4c47
.B binary
Packit cb4c47
the pattern
Packit cb4c47
.B q$ might
Packit cb4c47
match
Packit cb4c47
.B q
Packit cb4c47
immediately followed by a null byte, even though this
Packit cb4c47
is not matched when
Packit cb4c47
.I type
Packit cb4c47
is
Packit cb4c47
.BR text .
Packit cb4c47
Conversely, when
Packit cb4c47
.I type
Packit cb4c47
is
Packit cb4c47
.B binary
Packit cb4c47
the pattern
Packit cb4c47
.B .\&
Packit cb4c47
(period) might not match a null byte.
Packit cb4c47
.IP
Packit cb4c47
.I Warning:
Packit cb4c47
The
Packit cb4c47
.B \-a
Packit cb4c47
option might output binary garbage,
Packit cb4c47
which can have nasty side effects if the output is a terminal and if the
Packit cb4c47
terminal driver interprets some of it as commands.
Packit cb4c47
On the other hand, when reading files whose text encodings are
Packit cb4c47
unknown, it can be helpful to use
Packit cb4c47
.B \-a
Packit cb4c47
or to set
Packit cb4c47
.B LC_ALL='C'
Packit cb4c47
in the environment, in order to find more matches even if the matches
Packit cb4c47
are unsafe for direct display.
Packit cb4c47
.TP
Packit cb4c47
.BI \-D " ACTION" "\fR,\fP \-\^\-devices=" ACTION
Packit cb4c47
If an input file is a device, FIFO or socket, use
Packit cb4c47
.I ACTION
Packit cb4c47
to process it.
Packit cb4c47
By default,
Packit cb4c47
.I ACTION
Packit cb4c47
is
Packit cb4c47
.BR read ,
Packit cb4c47
which means that devices are read just as if they were ordinary files.
Packit cb4c47
If
Packit cb4c47
.I ACTION
Packit cb4c47
is
Packit cb4c47
.BR skip ,
Packit cb4c47
devices are silently skipped.
Packit cb4c47
.TP
Packit cb4c47
.BI \-d " ACTION" "\fR,\fP \-\^\-directories=" ACTION
Packit cb4c47
If an input file is a directory, use
Packit cb4c47
.I ACTION
Packit cb4c47
to process it.
Packit cb4c47
By default,
Packit cb4c47
.I ACTION
Packit cb4c47
is
Packit cb4c47
.BR read ,
Packit cb4c47
i.e., read directories just as if they were ordinary files.
Packit cb4c47
If
Packit cb4c47
.I ACTION
Packit cb4c47
is
Packit cb4c47
.BR skip ,
Packit cb4c47
silently skip directories.
Packit cb4c47
If
Packit cb4c47
.I ACTION
Packit cb4c47
is
Packit cb4c47
.BR recurse ,
Packit cb4c47
read all files under each directory, recursively,
Packit cb4c47
following symbolic links only if they are on the command line.
Packit cb4c47
This is equivalent to the
Packit cb4c47
.B \-r
Packit cb4c47
option.
Packit cb4c47
.TP
Packit cb4c47
.BI \-\^\-exclude= GLOB
Packit cb4c47
Skip any command-line file with a name suffix that matches the pattern
Packit cb4c47
.IR GLOB ,
Packit cb4c47
using wildcard matching; a name suffix is either the whole
Packit cb4c47
name, or any suffix starting after a
Packit cb4c47
.B /
Packit cb4c47
and before a +non-\fB/\fP.
Packit cb4c47
When searching recursively, skip any subfile whose base name matches
Packit cb4c47
.IR GLOB ;
Packit cb4c47
the base name is the part after the last
Packit cb4c47
.BR / .
Packit cb4c47
A pattern can use
Packit cb4c47
.BR * ,
Packit cb4c47
.BR ? ,
Packit cb4c47
and
Packit cb4c47
.BR [ ... ]
Packit cb4c47
as wildcards, and
Packit cb4c47
.B \e
Packit cb4c47
to quote a wildcard or backslash character literally.
Packit cb4c47
.TP
Packit cb4c47
.BI \-\^\-exclude-from= FILE
Packit cb4c47
Skip files whose base name matches any of the file-name globs read from
Packit cb4c47
.I FILE
Packit cb4c47
(using wildcard matching as described under
Packit cb4c47
.BR \-\^\-exclude ).
Packit cb4c47
.TP
Packit cb4c47
.BI \-\^\-exclude-dir= GLOB
Packit cb4c47
Skip any command-line directory with a name suffix that matches the
Packit cb4c47
pattern
Packit cb4c47
.IR GLOB .
Packit cb4c47
When searching recursively, skip any subdirectory
Packit cb4c47
whose base name matches
Packit cb4c47
.IR GLOB .
Packit cb4c47
Ignore any redundant trailing slashes in
Packit cb4c47
.IR GLOB .
Packit cb4c47
.TP
Packit cb4c47
.BR \-I
Packit cb4c47
Process a binary file as if it did not contain matching data; this is
Packit cb4c47
equivalent to the
Packit cb4c47
.B \-\^\-binary\-files=without-match
Packit cb4c47
option.
Packit cb4c47
.TP
Packit cb4c47
.BI \-\^\-include= GLOB
Packit cb4c47
Search only files whose base name matches
Packit cb4c47
.I GLOB
Packit cb4c47
(using wildcard matching as described under
Packit cb4c47
.BR \-\^\-exclude ).
Packit cb4c47
.TP
Packit cb4c47
.BR \-r ", " \-\^\-recursive
Packit cb4c47
Read all files under each directory, recursively,
Packit cb4c47
following symbolic links only if they are on the command line.
Packit cb4c47
Note that if no file operand is given, grep searches the working directory.
Packit cb4c47
This is equivalent to the
Packit cb4c47
.B "\-d recurse"
Packit cb4c47
option.
Packit cb4c47
.TP
Packit cb4c47
.BR \-R ", " \-\^\-dereference\-recursive
Packit cb4c47
Read all files under each directory, recursively.
Packit cb4c47
Follow all symbolic links, unlike
Packit cb4c47
.BR \-r .
Packit cb4c47
.SS "Other Options"
Packit cb4c47
.TP
Packit cb4c47
.BR \-\^\-line\-buffered
Packit cb4c47
Use line buffering on output.
Packit cb4c47
This can cause a performance penalty.
Packit cb4c47
.TP
Packit cb4c47
.BR \-U ", " \-\^\-binary
Packit cb4c47
Treat the file(s) as binary.
Packit cb4c47
By default, under MS-DOS and MS-Windows,
Packit cb4c47
.BR grep
Packit cb4c47
guesses whether a file is text or binary as described for the
Packit cb4c47
.B \-\^\-binary\-files
Packit cb4c47
option.
Packit cb4c47
If
Packit cb4c47
.BR grep
Packit cb4c47
decides the file is a text file, it strips the CR characters from the
Packit cb4c47
original file contents (to make regular expressions with
Packit cb4c47
.B ^
Packit cb4c47
and
Packit cb4c47
.B $
Packit cb4c47
work correctly).
Packit cb4c47
Specifying
Packit cb4c47
.B \-U
Packit cb4c47
overrules this guesswork, causing all files to be read and passed to the
Packit cb4c47
matching mechanism verbatim; if the file is a text file with CR/LF
Packit cb4c47
pairs at the end of each line, this will cause some regular
Packit cb4c47
expressions to fail.
Packit cb4c47
This option has no effect on platforms
Packit cb4c47
other than MS-DOS and MS-Windows.
Packit cb4c47
.TP
Packit cb4c47
.BR \-z ", " \-\^\-null\-data
Packit cb4c47
Treat input and output data as sequences of lines, each terminated by
Packit cb4c47
a zero byte (the ASCII NUL character) instead of a newline.
Packit cb4c47
Like the
Packit cb4c47
.B \-Z
Packit cb4c47
or
Packit cb4c47
.B \-\^\-null
Packit cb4c47
option, this option can be used with commands like
Packit cb4c47
.B sort -z
Packit cb4c47
to process arbitrary file names.
Packit cb4c47
.
Packit cb4c47
.SH "REGULAR EXPRESSIONS"
Packit cb4c47
A regular expression is a pattern that describes a set of strings.
Packit cb4c47
Regular expressions are constructed analogously to arithmetic
Packit cb4c47
expressions, by using various operators to combine smaller expressions.
Packit cb4c47
.PP
Packit cb4c47
.B grep
Packit cb4c47
understands three different versions of regular expression syntax:
Packit cb4c47
\*(lqbasic\*(rq (BRE), \*(lqextended\*(rq (ERE) and \*(lqperl\*(rq (PCRE).
Packit cb4c47
In GNU
Packit cb4c47
.B grep
Packit cb4c47
there is no difference in available functionality between basic and
Packit cb4c47
extended syntaxes.
Packit cb4c47
In other implementations, basic regular expressions are less powerful.
Packit cb4c47
The following description applies to extended regular expressions;
Packit cb4c47
differences for basic regular expressions are summarized afterwards.
Packit cb4c47
Perl-compatible regular expressions give additional functionality, and are
Packit cb4c47
documented in pcresyntax(3) and pcrepattern(3), but work only if
Packit cb4c47
PCRE is available in the system.
Packit cb4c47
.PP
Packit cb4c47
The fundamental building blocks are the regular expressions
Packit cb4c47
that match a single character.
Packit cb4c47
Most characters, including all letters and digits,
Packit cb4c47
are regular expressions that match themselves.
Packit cb4c47
Any meta-character with special meaning
Packit cb4c47
may be quoted by preceding it with a backslash.
Packit cb4c47
.PP
Packit cb4c47
The period
Packit cb4c47
.B .\&
Packit cb4c47
matches any single character.
Packit cb4c47
.SS "Character Classes and Bracket Expressions"
Packit cb4c47
A
Packit cb4c47
.I "bracket expression"
Packit cb4c47
is a list of characters enclosed by
Packit cb4c47
.B [
Packit cb4c47
and
Packit cb4c47
.BR ] .
Packit cb4c47
It matches any single
Packit cb4c47
character in that list; if the first character of the list
Packit cb4c47
is the caret
Packit cb4c47
.B ^
Packit cb4c47
then it matches any character
Packit cb4c47
.I not
Packit cb4c47
in the list.
Packit cb4c47
For example, the regular expression
Packit cb4c47
.B [0123456789]
Packit cb4c47
matches any single digit.
Packit cb4c47
.PP
Packit cb4c47
Within a bracket expression, a
Packit cb4c47
.I "range expression"
Packit cb4c47
consists of two characters separated by a hyphen.
Packit cb4c47
It matches any single character that sorts between the two characters,
Packit cb4c47
inclusive, using the locale's collating sequence and character set.
Packit cb4c47
For example, in the default C locale,
Packit cb4c47
.B [a\-d]
Packit cb4c47
is equivalent to
Packit cb4c47
.BR [abcd] .
Packit cb4c47
Many locales sort characters in dictionary order, and in these locales
Packit cb4c47
.B [a\-d]
Packit cb4c47
is typically not equivalent to
Packit cb4c47
.BR [abcd] ;
Packit cb4c47
it might be equivalent to
Packit cb4c47
.BR [aBbCcDd] ,
Packit cb4c47
for example.
Packit cb4c47
To obtain the traditional interpretation of bracket expressions,
Packit cb4c47
you can use the C locale by setting the
Packit cb4c47
.B LC_ALL
Packit cb4c47
environment variable to the value
Packit cb4c47
.BR C .
Packit cb4c47
.PP
Packit cb4c47
Finally, certain named classes of characters are predefined within
Packit cb4c47
bracket expressions, as follows.
Packit cb4c47
Their names are self explanatory, and they are
Packit cb4c47
.BR [:alnum:] ,
Packit cb4c47
.BR [:alpha:] ,
Packit cb4c47
.BR [:cntrl:] ,
Packit cb4c47
.BR [:digit:] ,
Packit cb4c47
.BR [:graph:] ,
Packit cb4c47
.BR [:lower:] ,
Packit cb4c47
.BR [:print:] ,
Packit cb4c47
.BR [:punct:] ,
Packit cb4c47
.BR [:space:] ,
Packit cb4c47
.BR [:upper:] ,
Packit cb4c47
and
Packit cb4c47
.BR [:xdigit:].
Packit cb4c47
For example,
Packit cb4c47
.B [[:alnum:]]
Packit cb4c47
means the character class of numbers and
Packit cb4c47
letters in the current locale.
Packit cb4c47
In the C locale and ASCII
Packit cb4c47
character set encoding, this is the same as
Packit cb4c47
.BR [0\-9A\-Za\-z] .
Packit cb4c47
(Note that the brackets in these class names are part of the symbolic
Packit cb4c47
names, and must be included in addition to the brackets delimiting
Packit cb4c47
the bracket expression.)
Packit cb4c47
Most meta-characters lose their special meaning inside bracket expressions.
Packit cb4c47
To include a literal
Packit cb4c47
.B ]
Packit cb4c47
place it first in the list.
Packit cb4c47
Similarly, to include a literal
Packit cb4c47
.B ^
Packit cb4c47
place it anywhere but first.
Packit cb4c47
Finally, to include a literal
Packit cb4c47
.B \-
Packit cb4c47
place it last.
Packit cb4c47
.SS Anchoring
Packit cb4c47
The caret
Packit cb4c47
.B ^
Packit cb4c47
and the dollar sign
Packit cb4c47
.B $
Packit cb4c47
are meta-characters that respectively match the empty string at the
Packit cb4c47
beginning and end of a line.
Packit cb4c47
.SS "The Backslash Character and Special Expressions"
Packit cb4c47
The symbols
Packit cb4c47
.B \e<
Packit cb4c47
and
Packit cb4c47
.B \e>
Packit cb4c47
respectively match the empty string at the beginning and end of a word.
Packit cb4c47
The symbol
Packit cb4c47
.B \eb
Packit cb4c47
matches the empty string at the edge of a word,
Packit cb4c47
and
Packit cb4c47
.B \eB
Packit cb4c47
matches the empty string provided it's
Packit cb4c47
.I not
Packit cb4c47
at the edge of a word.
Packit cb4c47
The symbol
Packit cb4c47
.B \ew
Packit cb4c47
is a synonym for
Packit cb4c47
.B [_[:alnum:]]
Packit cb4c47
and
Packit cb4c47
.B \eW
Packit cb4c47
is a synonym for
Packit cb4c47
.BR [^_[:alnum:]] .
Packit cb4c47
.SS Repetition
Packit cb4c47
A regular expression may be followed by one of several repetition operators:
Packit cb4c47
.PD 0
Packit cb4c47
.TP
Packit cb4c47
.B ?
Packit cb4c47
The preceding item is optional and matched at most once.
Packit cb4c47
.TP
Packit cb4c47
.B *
Packit cb4c47
The preceding item will be matched zero or more times.
Packit cb4c47
.TP
Packit cb4c47
.B +
Packit cb4c47
The preceding item will be matched one or more times.
Packit cb4c47
.TP
Packit cb4c47
.BI { n }
Packit cb4c47
The preceding item is matched exactly
Packit cb4c47
.I n
Packit cb4c47
times.
Packit cb4c47
.TP
Packit cb4c47
.BI { n ,}
Packit cb4c47
The preceding item is matched
Packit cb4c47
.I n
Packit cb4c47
or more times.
Packit cb4c47
.TP
Packit cb4c47
.BI {, m }
Packit cb4c47
The preceding item is matched at most
Packit cb4c47
.I m
Packit cb4c47
times.
Packit cb4c47
This is a GNU extension.
Packit cb4c47
.TP
Packit cb4c47
.BI { n , m }
Packit cb4c47
The preceding item is matched at least
Packit cb4c47
.I n
Packit cb4c47
times, but not more than
Packit cb4c47
.I m
Packit cb4c47
times.
Packit cb4c47
.PD
Packit cb4c47
.SS Concatenation
Packit cb4c47
Two regular expressions may be concatenated; the resulting
Packit cb4c47
regular expression matches any string formed by concatenating
Packit cb4c47
two substrings that respectively match the concatenated
Packit cb4c47
expressions.
Packit cb4c47
.SS Alternation
Packit cb4c47
Two regular expressions may be joined by the infix operator
Packit cb4c47
.BR | ;
Packit cb4c47
the resulting regular expression matches any string matching
Packit cb4c47
either alternate expression.
Packit cb4c47
.SS Precedence
Packit cb4c47
Repetition takes precedence over concatenation, which in turn
Packit cb4c47
takes precedence over alternation.
Packit cb4c47
A whole expression may be enclosed in parentheses
Packit cb4c47
to override these precedence rules and form a subexpression.
Packit cb4c47
.SS "Back References and Subexpressions"
Packit cb4c47
The back-reference
Packit cb4c47
.BI \e n\c
Packit cb4c47
\&, where
Packit cb4c47
.I n
Packit cb4c47
is a single digit, matches the substring
Packit cb4c47
previously matched by the
Packit cb4c47
.IR n th
Packit cb4c47
parenthesized subexpression of the regular expression.
Packit cb4c47
.SS "Basic vs Extended Regular Expressions"
Packit cb4c47
In basic regular expressions the meta-characters
Packit cb4c47
.BR ? ,
Packit cb4c47
.BR + ,
Packit cb4c47
.BR { ,
Packit cb4c47
.BR | ,
Packit cb4c47
.BR ( ,
Packit cb4c47
and
Packit cb4c47
.BR )
Packit cb4c47
lose their special meaning; instead use the backslashed
Packit cb4c47
versions
Packit cb4c47
.BR \e? ,
Packit cb4c47
.BR \e+ ,
Packit cb4c47
.BR \e{ ,
Packit cb4c47
.BR \e| ,
Packit cb4c47
.BR \e( ,
Packit cb4c47
and
Packit cb4c47
.BR \e) .
Packit cb4c47
.
Packit cb4c47
.SH "ENVIRONMENT VARIABLES"
Packit cb4c47
The behavior of
Packit cb4c47
.B grep
Packit cb4c47
is affected by the following environment variables.
Packit cb4c47
.PP
Packit cb4c47
The locale for category
Packit cb4c47
.BI LC_ foo
Packit cb4c47
is specified by examining the three environment variables
Packit cb4c47
.BR LC_ALL ,
Packit cb4c47
.BR LC_\fIfoo\fP ,
Packit cb4c47
.BR LANG ,
Packit cb4c47
in that order.
Packit cb4c47
The first of these variables that is set specifies the locale.
Packit cb4c47
For example, if
Packit cb4c47
.B LC_ALL
Packit cb4c47
is not set, but
Packit cb4c47
.B LC_MESSAGES
Packit cb4c47
is set to
Packit cb4c47
.BR pt_BR ,
Packit cb4c47
then the Brazilian Portuguese locale is used for the
Packit cb4c47
.B LC_MESSAGES
Packit cb4c47
category.
Packit cb4c47
The C locale is used if none of these environment variables are set,
Packit cb4c47
if the locale catalog is not installed, or if
Packit cb4c47
.B grep
Packit cb4c47
was not compiled with national language support (NLS).
Packit cb4c47
The shell command
Packit cb4c47
.B "locale \-a"
Packit cb4c47
lists locales that are currently available.
Packit cb4c47
.TP
Packit cb4c47
.B GREP_OPTIONS
Packit cb4c47
This variable specifies default options
Packit cb4c47
to be placed in front of any explicit options.
Packit cb4c47
As this causes problems when writing portable scripts,
Packit cb4c47
this feature will be removed in a future release of
Packit cb4c47
.BR grep ,
Packit cb4c47
and
Packit cb4c47
.B grep
Packit cb4c47
warns if it is used.
Packit cb4c47
Please use an alias or script instead.
Packit cb4c47
.TP
Packit cb4c47
.B GREP_COLOR
Packit cb4c47
This variable specifies the color used to highlight matched (non-empty) text.
Packit cb4c47
It is deprecated in favor of
Packit cb4c47
.BR GREP_COLORS ,
Packit cb4c47
but still supported.
Packit cb4c47
The
Packit cb4c47
.BR mt ,
Packit cb4c47
.BR ms ,
Packit cb4c47
and
Packit cb4c47
.B mc
Packit cb4c47
capabilities of
Packit cb4c47
.B GREP_COLORS
Packit cb4c47
have priority over it.
Packit cb4c47
It can only specify the color used to highlight
Packit cb4c47
the matching non-empty text in any matching line
Packit cb4c47
(a selected line when the
Packit cb4c47
.B -v
Packit cb4c47
command-line option is omitted,
Packit cb4c47
or a context line when
Packit cb4c47
.B -v
Packit cb4c47
is specified).
Packit cb4c47
The default is
Packit cb4c47
.BR 01;31 ,
Packit cb4c47
which means a bold red foreground text on the terminal's default background.
Packit cb4c47
.TP
Packit cb4c47
.B GREP_COLORS
Packit cb4c47
Specifies the colors and other attributes
Packit cb4c47
used to highlight various parts of the output.
Packit cb4c47
Its value is a colon-separated list of capabilities
Packit cb4c47
that defaults to
Packit cb4c47
.B ms=01;31:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36
Packit cb4c47
with the
Packit cb4c47
.B rv
Packit cb4c47
and
Packit cb4c47
.B ne
Packit cb4c47
boolean capabilities omitted (i.e., false).
Packit cb4c47
Supported capabilities are as follows.
Packit cb4c47
.RS
Packit cb4c47
.TP
Packit cb4c47
.B sl=
Packit cb4c47
SGR substring for whole selected lines
Packit cb4c47
(i.e.,
Packit cb4c47
matching lines when the
Packit cb4c47
.B \-v
Packit cb4c47
command-line option is omitted,
Packit cb4c47
or non-matching lines when
Packit cb4c47
.B \-v
Packit cb4c47
is specified).
Packit cb4c47
If however the boolean
Packit cb4c47
.B rv
Packit cb4c47
capability
Packit cb4c47
and the
Packit cb4c47
.B \-v
Packit cb4c47
command-line option are both specified,
Packit cb4c47
it applies to context matching lines instead.
Packit cb4c47
The default is empty (i.e., the terminal's default color pair).
Packit cb4c47
.TP
Packit cb4c47
.B cx=
Packit cb4c47
SGR substring for whole context lines
Packit cb4c47
(i.e.,
Packit cb4c47
non-matching lines when the
Packit cb4c47
.B \-v
Packit cb4c47
command-line option is omitted,
Packit cb4c47
or matching lines when
Packit cb4c47
.B \-v
Packit cb4c47
is specified).
Packit cb4c47
If however the boolean
Packit cb4c47
.B rv
Packit cb4c47
capability
Packit cb4c47
and the
Packit cb4c47
.B \-v
Packit cb4c47
command-line option are both specified,
Packit cb4c47
it applies to selected non-matching lines instead.
Packit cb4c47
The default is empty (i.e., the terminal's default color pair).
Packit cb4c47
.TP
Packit cb4c47
.B rv
Packit cb4c47
Boolean value that reverses (swaps) the meanings of
Packit cb4c47
the
Packit cb4c47
.B sl=
Packit cb4c47
and
Packit cb4c47
.B cx=
Packit cb4c47
capabilities
Packit cb4c47
when the
Packit cb4c47
.B \-v
Packit cb4c47
command-line option is specified.
Packit cb4c47
The default is false (i.e., the capability is omitted).
Packit cb4c47
.TP
Packit cb4c47
.B mt=01;31
Packit cb4c47
SGR substring for matching non-empty text in any matching line
Packit cb4c47
(i.e.,
Packit cb4c47
a selected line when the
Packit cb4c47
.B \-v
Packit cb4c47
command-line option is omitted,
Packit cb4c47
or a context line when
Packit cb4c47
.B \-v
Packit cb4c47
is specified).
Packit cb4c47
Setting this is equivalent to setting both
Packit cb4c47
.B ms=
Packit cb4c47
and
Packit cb4c47
.B mc=
Packit cb4c47
at once to the same value.
Packit cb4c47
The default is a bold red text foreground over the current line background.
Packit cb4c47
.TP
Packit cb4c47
.B ms=01;31
Packit cb4c47
SGR substring for matching non-empty text in a selected line.
Packit cb4c47
(This is only used when the
Packit cb4c47
.B \-v
Packit cb4c47
command-line option is omitted.)
Packit cb4c47
The effect of the
Packit cb4c47
.B sl=
Packit cb4c47
(or
Packit cb4c47
.B cx=
Packit cb4c47
if
Packit cb4c47
.BR rv )
Packit cb4c47
capability remains active when this kicks in.
Packit cb4c47
The default is a bold red text foreground over the current line background.
Packit cb4c47
.TP
Packit cb4c47
.B mc=01;31
Packit cb4c47
SGR substring for matching non-empty text in a context line.
Packit cb4c47
(This is only used when the
Packit cb4c47
.B \-v
Packit cb4c47
command-line option is specified.)
Packit cb4c47
The effect of the
Packit cb4c47
.B cx=
Packit cb4c47
(or
Packit cb4c47
.B sl=
Packit cb4c47
if
Packit cb4c47
.BR rv )
Packit cb4c47
capability remains active when this kicks in.
Packit cb4c47
The default is a bold red text foreground over the current line background.
Packit cb4c47
.TP
Packit cb4c47
.B fn=35
Packit cb4c47
SGR substring for file names prefixing any content line.
Packit cb4c47
The default is a magenta text foreground over the terminal's default background.
Packit cb4c47
.TP
Packit cb4c47
.B ln=32
Packit cb4c47
SGR substring for line numbers prefixing any content line.
Packit cb4c47
The default is a green text foreground over the terminal's default background.
Packit cb4c47
.TP
Packit cb4c47
.B bn=32
Packit cb4c47
SGR substring for byte offsets prefixing any content line.
Packit cb4c47
The default is a green text foreground over the terminal's default background.
Packit cb4c47
.TP
Packit cb4c47
.B se=36
Packit cb4c47
SGR substring for separators that are inserted
Packit cb4c47
between selected line fields
Packit cb4c47
.RB ( : ),
Packit cb4c47
between context line fields,
Packit cb4c47
.RB ( \- ),
Packit cb4c47
and between groups of adjacent lines when nonzero context is specified
Packit cb4c47
.RB ( \-\^\- ).
Packit cb4c47
The default is a cyan text foreground over the terminal's default background.
Packit cb4c47
.TP
Packit cb4c47
.B ne
Packit cb4c47
Boolean value that prevents clearing to the end of line
Packit cb4c47
using Erase in Line (EL) to Right
Packit cb4c47
.RB ( \\\\\\33[K )
Packit cb4c47
each time a colorized item ends.
Packit cb4c47
This is needed on terminals on which EL is not supported.
Packit cb4c47
It is otherwise useful on terminals
Packit cb4c47
for which the
Packit cb4c47
.B back_color_erase
Packit cb4c47
.RB ( bce )
Packit cb4c47
boolean terminfo capability does not apply,
Packit cb4c47
when the chosen highlight colors do not affect the background,
Packit cb4c47
or when EL is too slow or causes too much flicker.
Packit cb4c47
The default is false (i.e., the capability is omitted).
Packit cb4c47
.PP
Packit cb4c47
Note that boolean capabilities have no
Packit cb4c47
.BR = ...
Packit cb4c47
part.
Packit cb4c47
They are omitted (i.e., false) by default and become true when specified.
Packit cb4c47
.PP
Packit cb4c47
See the Select Graphic Rendition (SGR) section
Packit cb4c47
in the documentation of the text terminal that is used
Packit cb4c47
for permitted values and their meaning as character attributes.
Packit cb4c47
These substring values are integers in decimal representation
Packit cb4c47
and can be concatenated with semicolons.
Packit cb4c47
.B grep
Packit cb4c47
takes care of assembling the result
Packit cb4c47
into a complete SGR sequence
Packit cb4c47
.RB ( \\\\\\33[ ... m ).
Packit cb4c47
Common values to concatenate include
Packit cb4c47
.B 1
Packit cb4c47
for bold,
Packit cb4c47
.B 4
Packit cb4c47
for underline,
Packit cb4c47
.B 5
Packit cb4c47
for blink,
Packit cb4c47
.B 7
Packit cb4c47
for inverse,
Packit cb4c47
.B 39
Packit cb4c47
for default foreground color,
Packit cb4c47
.B 30
Packit cb4c47
to
Packit cb4c47
.B 37
Packit cb4c47
for foreground colors,
Packit cb4c47
.B 90
Packit cb4c47
to
Packit cb4c47
.B 97
Packit cb4c47
for 16-color mode foreground colors,
Packit cb4c47
.B 38;5;0
Packit cb4c47
to
Packit cb4c47
.B 38;5;255
Packit cb4c47
for 88-color and 256-color modes foreground colors,
Packit cb4c47
.B 49
Packit cb4c47
for default background color,
Packit cb4c47
.B 40
Packit cb4c47
to
Packit cb4c47
.B 47
Packit cb4c47
for background colors,
Packit cb4c47
.B 100
Packit cb4c47
to
Packit cb4c47
.B 107
Packit cb4c47
for 16-color mode background colors, and
Packit cb4c47
.B 48;5;0
Packit cb4c47
to
Packit cb4c47
.B 48;5;255
Packit cb4c47
for 88-color and 256-color modes background colors.
Packit cb4c47
.RE
Packit cb4c47
.TP
Packit cb4c47
\fBLC_ALL\fP, \fBLC_COLLATE\fP, \fBLANG\fP
Packit cb4c47
These variables specify the locale for the
Packit cb4c47
.B LC_COLLATE
Packit cb4c47
category,
Packit cb4c47
which determines the collating sequence
Packit cb4c47
used to interpret range expressions like
Packit cb4c47
.BR [a\-z] .
Packit cb4c47
.TP
Packit cb4c47
\fBLC_ALL\fP, \fBLC_CTYPE\fP, \fBLANG\fP
Packit cb4c47
These variables specify the locale for the
Packit cb4c47
.B LC_CTYPE
Packit cb4c47
category,
Packit cb4c47
which determines the type of characters,
Packit cb4c47
e.g., which characters are whitespace.
Packit cb4c47
This category also determines the character encoding, that is, whether
Packit cb4c47
text is encoded in UTF-8, ASCII, or some other encoding.  In the C or
Packit cb4c47
POSIX locale, all characters are encoded as a single byte and every
Packit cb4c47
byte is a valid character.
Packit cb4c47
.TP
Packit cb4c47
\fBLC_ALL\fP, \fBLC_MESSAGES\fP, \fBLANG\fP
Packit cb4c47
These variables specify the locale for the
Packit cb4c47
.B LC_MESSAGES
Packit cb4c47
category,
Packit cb4c47
which determines the language that
Packit cb4c47
.B grep
Packit cb4c47
uses for messages.
Packit cb4c47
The default C locale uses American English messages.
Packit cb4c47
.TP
Packit cb4c47
.B POSIXLY_CORRECT
Packit cb4c47
If set,
Packit cb4c47
.B grep
Packit cb4c47
behaves as POSIX requires; otherwise,
Packit cb4c47
.B grep
Packit cb4c47
behaves more like other GNU programs.
Packit cb4c47
POSIX requires that options that follow file names must be
Packit cb4c47
treated as file names; by default, such options are permuted to the
Packit cb4c47
front of the operand list and are treated as options.
Packit cb4c47
Also, POSIX requires that unrecognized options be diagnosed as
Packit cb4c47
\*(lqillegal\*(rq, but since they are not really against the law the default
Packit cb4c47
is to diagnose them as \*(lqinvalid\*(rq.
Packit cb4c47
.B POSIXLY_CORRECT
Packit cb4c47
also disables \fB_\fP\fIN\fP\fB_GNU_nonoption_argv_flags_\fP,
Packit cb4c47
described below.
Packit cb4c47
.TP
Packit cb4c47
\fB_\fP\fIN\fP\fB_GNU_nonoption_argv_flags_\fP
Packit cb4c47
(Here
Packit cb4c47
.I N
Packit cb4c47
is
Packit cb4c47
.BR grep 's
Packit cb4c47
numeric process ID.)  If the
Packit cb4c47
.IR i th
Packit cb4c47
character of this environment variable's value is
Packit cb4c47
.BR 1 ,
Packit cb4c47
do not consider the
Packit cb4c47
.IR i th
Packit cb4c47
operand of
Packit cb4c47
.B grep
Packit cb4c47
to be an option, even if it appears to be one.
Packit cb4c47
A shell can put this variable in the environment for each command it runs,
Packit cb4c47
specifying which operands are the results of file name wildcard
Packit cb4c47
expansion and therefore should not be treated as options.
Packit cb4c47
This behavior is available only with the GNU C library, and only
Packit cb4c47
when
Packit cb4c47
.B POSIXLY_CORRECT
Packit cb4c47
is not set.
Packit cb4c47
.
Packit cb4c47
.SH "EXIT STATUS"
Packit cb4c47
Normally the exit status is 0 if a line is selected, 1 if no lines
Packit cb4c47
were selected, and 2 if an error occurred.  However, if the
Packit cb4c47
.B \-q
Packit cb4c47
or
Packit cb4c47
.B \-\^\-quiet
Packit cb4c47
or
Packit cb4c47
.B \-\^\-silent
Packit cb4c47
is used and a line is selected, the exit status is 0 even if an error
Packit cb4c47
occurred.
Packit cb4c47
.
Packit cb4c47
.SH COPYRIGHT
Packit cb4c47
Copyright 1998\(en2000, 2002, 2005\(en2017 Free Software Foundation, Inc.
Packit cb4c47
.PP
Packit cb4c47
This is free software;
Packit cb4c47
see the source for copying conditions.
Packit cb4c47
There is NO warranty;
Packit cb4c47
not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Packit cb4c47
.
Packit cb4c47
.SH BUGS
Packit cb4c47
.SS "Reporting Bugs"
Packit cb4c47
Email bug reports to
Packit cb4c47
.MTO bug-grep@gnu.org "the bug-reporting address" .
Packit cb4c47
An
Packit cb4c47
.URL http://lists.gnu.org/mailman/listinfo/bug-grep "email archive"
Packit cb4c47
and a
Packit cb4c47
.URL http://debbugs.gnu.org/cgi/pkgreport.cgi?package=grep "bug tracker"
Packit cb4c47
are available.
Packit cb4c47
.SS "Known Bugs"
Packit cb4c47
Large repetition counts in the
Packit cb4c47
.BI { n , m }
Packit cb4c47
construct may cause
Packit cb4c47
.B grep
Packit cb4c47
to use lots of memory.
Packit cb4c47
In addition,
Packit cb4c47
certain other obscure regular expressions require exponential time
Packit cb4c47
and space, and may cause
Packit cb4c47
.B grep
Packit cb4c47
to run out of memory.
Packit cb4c47
.PP
Packit cb4c47
Back-references are very slow, and may require exponential time.
Packit cb4c47
.
Packit cb4c47
.SH "SEE ALSO"
Packit cb4c47
.SS "Regular Manual Pages"
Packit cb4c47
awk(1), cmp(1), diff(1), find(1), gzip(1),
Packit cb4c47
perl(1), sed(1), sort(1), xargs(1), zgrep(1),
Packit cb4c47
read(2),
Packit cb4c47
pcre(3), pcresyntax(3), pcrepattern(3),
Packit cb4c47
terminfo(5),
Packit cb4c47
glob(7), regex(7).
Packit cb4c47
.SS "POSIX Programmer's Manual Page"
Packit cb4c47
grep(1p).
Packit cb4c47
.SS "Full Documentation"
Packit cb4c47
A
Packit cb4c47
.URL http://www.gnu.org/software/grep/manual/ "complete manual"
Packit cb4c47
is available.
Packit cb4c47
If the
Packit cb4c47
.B info
Packit cb4c47
and
Packit cb4c47
.B grep
Packit cb4c47
programs are properly installed at your site, the command
Packit cb4c47
.IP
Packit cb4c47
.B info grep
Packit cb4c47
.PP
Packit cb4c47
should give you access to the complete manual.
Packit cb4c47
.
Packit cb4c47
.SH NOTES
Packit cb4c47
This man page is maintained only fitfully;
Packit cb4c47
the full documentation is often more up-to-date.
Packit cb4c47
.\" Work around problems with some troff -man implementations.
Packit cb4c47
.br