summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/grep/grep.1
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/usr.bin/grep/grep.1')
-rw-r--r--gnu/usr.bin/grep/grep.1312
1 files changed, 169 insertions, 143 deletions
diff --git a/gnu/usr.bin/grep/grep.1 b/gnu/usr.bin/grep/grep.1
index 995439f..26ce985 100644
--- a/gnu/usr.bin/grep/grep.1
+++ b/gnu/usr.bin/grep/grep.1
@@ -13,93 +13,39 @@
.de Id
.ds Dt \\$4
..
-.Id $Id: grep.1,v 1.8 2000/01/17 00:55:06 alainm Exp $
+.Id $Id: grep.1,v 1.9 2000/01/26 03:42:16 alainm Exp $
.TH GREP 1 \*(Dt "GNU Project"
.SH NAME
grep, egrep, fgrep, zgrep \- print lines matching a pattern
.SH SYNOPSIS
.B grep
-.RB [ \- [ ABC ]
-.IR NUM ]
-.RB [ \-EFGHLUVZabchilnqrsuvwxyz ]
+.RI [ options ]
+.I PATTERN
+.RI [ FILE .\|.\|.]
+.br
+.B grep
+.RI [ options ]
.RB [ \-e
.I PATTERN
|
.B \-f
.IR FILE ]
-.RB [ \-d
-.IR ACTION ]
-.RB [ \-\^\-binary-files=\fITYPE\fP ]
-.RB [ \-\^\-directories=\fIACTION\fP ]
-.RB [ \-\^\-extended-regexp ]
-.RB [ \-\^\-fixed-strings ]
-.RB [ \-\^\-basic-regexp ]
-.RB [ \-\^\-regexp=\fIPATTERN\fP ]
-.RB [ \-\^\-file=\fIFILE\fP ]
-.RB [ \-\^\-ignore-case ]
-.RB [ \-\^\-word-regexp ]
-.RB [ \-\^\-line-regexp ]
-.RB [ \-\^\-line-regexp ]
-.RB [ \-\^\-no-messages ]
-.RB [ \-\^\-invert-match ]
-.RB [ \-\^\-version ]
-.RB [ \-\^\-help ]
-.RB [ \-\^\-byte-offset ]
-.RB [ \-\^\-line-number ]
-.RB [ \-\^\-with-filename ]
-.RB [ \-\^\-no-filename ]
-.RB [ \-\^\-quiet ]
-.RB [ \-\^\-silent ]
-.RB [ \-\^\-text ]
-.RB [ \-\^\-files-without-match ]
-.RB [ \-\^\-files-with-matches ]
-.RB [ \-\^\-count ]
-.RB [ \-\^\-before-context=\fINUM\fP ]
-.RB [ \-\^\-after-context=\fINUM\fP ]
-.RB [ \-\^\-context [ =\fINUM\fP ]]
-.RB [ \-\^\-binary ]
-.RB [ \-\^\-unix-byte-offsets ]
-.RB [ \-\^\-mmap ]
-.RB [ \-\^\-null ]
-.RB [ \-\^\-recursive ]
-.RB [ \-\^\-decompress ]
-.RI [ file .\|.\|.]
+.RI [ FILE .\|.\|.]
.SH DESCRIPTION
.PP
.B grep
searches the named input
-.I files
+.IR FILE s
(or standard input if no files are named, or
the file name
.B \-
is given)
for lines containing a match to the given
-.IR pattern .
+.IR PATTERN .
By default,
.B grep
prints the matching lines.
.PP
-There are three major variants of
-.BR grep ,
-controlled by the following options.
-.PD 0
-.TP
-.BR \-G ", " \-\^\-basic-regexp
-Interpret
-.I pattern
-as a basic regular expression (see below). This is the default.
-.TP
-.BR \-E ", " \-\^\-extended-regexp
-Interpret
-.I pattern
-as an extended regular expression (see below).
-.TP
-.BR \-F ", " \-\^\-fixed-strings
-Interpret
-.I pattern
-as a list of fixed strings, separated by newlines,
-any of which is to be matched.
-.PP
In addition, two variant programs
.B egrep
and
@@ -114,40 +60,31 @@ is the same as
.B zgrep
is the same as
.BR "grep\ \-Z" .
-.PD
-.PP
-All variants of
-.B grep
-understand the following options:
-.PD 0
+.SH OPTIONS
.TP
.BI \-A " NUM" "\fR,\fP \-\^\-after-context=" NUM
Print
.I NUM
lines of trailing context after matching lines.
.TP
+.BR \-a ", " \-\^\-text
+Process a binary file as if it were text; this is equivalent to the
+.B \-\^\-binary-files=text
+option.
+.TP
.BI \-B " NUM" "\fR,\fP \-\^\-before-context=" NUM
Print
.I NUM
lines of leading context before matching lines.
.TP
-.BI \-C " \fR[\fPNUM\fR]\fP" "\fR,\fP \-\^\-context\fR[\fP=" NUM\fR]\fP
+\fB\-C\fP [\fINUM\fP], \fB\-\fP\fINUM\fP, \fB\-\^\-context\fP[\fB=\fP\fINUM\fP]
Print
.I NUM
lines (default 2) of output context.
.TP
-.BI \- NUM
-Same as
-.BI \-\^\-context= NUM
-lines of leading and trailing context. However,
-.B grep
-will never print any given line more than once.
-.TP
-.BR \-V ", " \-\^\-version
-Print the version number of
-.B grep
-to standard error. This version number should
-be included in all bug reports (see below).
+.BR \-b ", " \-\^\-byte-offset
+Print the byte offset within the input file before
+each line of output.
.TP
.BI \-\^\-binary-files= TYPE
If the first few bytes of a file indicate that the file contains binary
@@ -167,7 +104,9 @@ If
is
.BR without-match ,
.B grep
-assumes that a binary file does not match.
+assumes that a binary file does not match; this is equivalent to the
+.B \-I
+option.
If
.I TYPE
is
@@ -175,8 +114,6 @@ is
.B grep
processes a binary file as if it were text; this is equivalent to the
.B \-a
-or
-.B \-\^\-text
option.
.I Warning:
.B "grep \-\^\-binary-files=text"
@@ -184,10 +121,6 @@ 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.
.TP
-.BR \-b ", " \-\^\-byte-offset
-Print the byte offset within the input file before
-each line of output.
-.TP
.BR \-c ", " \-\^\-count
Suppress normal output; instead print a count of
matching lines for each input file.
@@ -218,18 +151,34 @@ this is equivalent to the
.B \-r
option.
.TP
+.BR \-E ", " \-\^\-extended-regexp
+Interpret
+.I PATTERN
+as an extended regular expression (see below).
+.TP
.BI \-e " PATTERN" "\fR,\fP \-\^\-regexp=" PATTERN
Use
.I PATTERN
as the pattern; useful to protect patterns beginning with
.BR \- .
.TP
+.BR \-F ", " \-\^\-fixed-strings
+Interpret
+.I PATTERN
+as a list of fixed strings, separated by newlines,
+any of which is to be matched.
+.TP
.BI \-f " FILE" "\fR,\fP \-\^\-file=" FILE
Obtain patterns from
.IR FILE ,
one per line.
The empty file contains zero patterns, and therfore matches nothing.
.TP
+.BR \-G ", " \-\^\-basic-regexp
+Interpret
+.I PATTERN
+as a basic regular expression (see below). This is the default.
+.TP
.BR \-H ", " \-\^\-with-filename
Print the filename for each match.
.TP
@@ -237,9 +186,18 @@ Print the filename for each match.
Suppress the prefixing of filenames on output
when multiple files are searched.
.TP
+.B \-\^\-help
+Output a brief help message.
+.TP
+.BR \-I
+Process a binary file as if it did not contain matching data; this is
+equivalent to the
+.B \-\^\-binary-files=without-match
+option.
+.TP
.BR \-i ", " \-\^\-ignore-case
Ignore case distinctions in both the
-.I pattern
+.I PATTERN
and the input files.
.TP
.BR \-L ", " \-\^\-files-without-match
@@ -254,6 +212,21 @@ the name of each input file from which output
would normally have been printed. The scanning will
stop on the first match.
.TP
+.B \-\^\-mmap
+If possible, use the
+.BR mmap (2)
+system call to read input, instead of
+the default
+.BR read (2)
+system call. In some situations,
+.B \-\^\-mmap
+yields better performance. However,
+.B \-\^\-mmap
+can cause undefined behavior (including core dumps)
+if an input file shrinks while
+.B grep
+is operating, or if an I/O error occurs.
+.TP
.BR \-n ", " \-\^\-line-number
Prefix each line of output with the line number
within its input file.
@@ -297,29 +270,6 @@ and
.B \-s
and should redirect output to /dev/null instead.
.TP
-.BR \-a ", " \-\^\-text
-Process a binary file as if it were text; this is equivalent to the
-.B \-\^\-binary-files=text
-option.
-.TP
-.BR \-v ", " \-\^\-invert-match
-Invert the sense of matching, to select non-matching lines.
-.TP
-.BR \-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.
-.TP
-.BR \-x ", " \-\^\-line-regexp
-Select only those matches that exactly match the whole line.
-.TP
-.B \-y
-Obsolete synonym for
-.BR \-i .
-.TP
.BR \-U ", " \-\^\-binary
Treat the file(s) as binary. By default, under MS-DOS and MS-Windows,
.BR grep
@@ -351,20 +301,29 @@ on a Unix machine. This option has no effect unless
option is also used;
it has no effect on platforms other than MS-DOS and MS-Windows.
.TP
-.B \-\^\-mmap
-If possible, use the
-.BR mmap (2)
-system call to read input, instead of
-the default
-.BR read (2)
-system call. In some situations,
-.B \-\^\-mmap
-yields better performance. However,
-.B \-\^\-mmap
-can cause undefined behavior (including core dumps)
-if an input file shrinks while
+.BR \-V ", " \-\^\-version
+Print the version number of
.B grep
-is operating, or if an I/O error occurs.
+to standard error. This version number should
+be included in all bug reports (see below).
+.TP
+.BR \-v ", " \-\^\-invert-match
+Invert the sense of matching, to select non-matching lines.
+.TP
+.BR \-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.
+.TP
+.BR \-x ", " \-\^\-line-regexp
+Select only those matches that exactly match the whole line.
+.TP
+.B \-y
+Obsolete synonym for
+.BR \-i .
.TP
.BR \-Z ", " \-\^\-null
Output a zero byte (the \s-1ASCII\s0
@@ -383,14 +342,10 @@ and
.B "xargs \-0"
to process arbitrary file names,
even those that contain newline characters.
-.PD
-.LP
-Following option is only available if compiled with zlib(3) library:
-.PD 0
.TP
-.B \-Z, --decompress
+.BR \-Z ", " \-\^\-decompress
Decompress the input data before searching.
-.PD
+This option is only available if compiled with zlib(3) library.
.SH "REGULAR EXPRESSIONS"
.PP
A regular expression is a pattern that describes a set of strings.
@@ -424,7 +379,7 @@ then it matches any character
in the list.
For example, the regular expression
.B [0123456789]
-matches any single digit. A range of ASCII characters
+matches any single digit. A range of characters
may be specified by giving the first and last characters, separated
by a hyphen.
Finally, certain named classes of characters are predefined.
@@ -445,8 +400,9 @@ For example,
.B [[:alnum:]]
means
.BR [0-9A-Za-z] ,
-except the latter form is dependent upon the ASCII character encoding,
-whereas the former is portable.
+except the latter form depends upon the \s-1POSIX\s0 locale and the
+\s-1ASCII\s0 character encoding, whereas the former is independent
+of locale and character set.
(Note that the brackets in these class names are part of the symbolic
names, and must be included in addition to the brackets delimiting
the bracket list.) Most metacharacters lose their special meaning
@@ -590,14 +546,84 @@ searches for the two-character string
instead of reporting a syntax error in the regular expression.
\s-1POSIX.2\s0 allows this behavior as an extension, but portable scripts
should avoid it.
-.SH ENVIRONMENT
-The environment variable
+.SH "ENVIRONMENT VARIABLES"
+.TP
+.B GREP_OPTIONS
+This variable specifies default options to be placed in front of any
+explicit options. For example, if
.B GREP_OPTIONS
-can hold a set of default
-options for
-.I grep.
-These options are interpreted first and can be overwritten by explicit command
-line parameters.
+is
+.BR "'\-\^\-binary-files=without-match \-\^\-directories=skip'" ,
+.B grep
+behaves as if the two options
+.B \-\^\-binary-files=without-match
+and
+.B \-\^\-directories=skip
+had been specified before any explicit options.
+Option specifications are separated by whitespace.
+A backslash escapes the next character,
+so it can be used to specify an option containing whitespace or a backslash.
+.TP
+\fBLC_ALL\fP, \fBLC_MESSAGES\fP, \fBLANG\fP
+These variables specify the
+.B LC_MESSAGES
+locale, which determines the language that
+.B grep
+uses for messages.
+The locale is determined by the first of these variables that is set.
+American English is used if none of these environment variables are set,
+or if the message catalog is not installed, or if
+.B grep
+was not compiled with national language support (\s-1NLS\s0).
+.TP
+\fBLC_ALL\fP, \fBLC_CTYPE\fP, \fBLANG\fP
+These variables specify the
+.B LC_CTYPE
+locale, which determines the type of characters, e.g., which
+characters are whitespace.
+The locale is determined by the first of these variables that is set.
+The \s-1POSIX\s0 locale is used if none of these environment variables
+are set, or if the locale catalog is not installed, or if
+.B grep
+was not compiled with national language support (\s-1NLS\s0).
+.TP
+.B POSIXLY_CORRECT
+If set,
+.B grep
+behaves as \s-1POSIX.2\s0 requires; otherwise,
+.B grep
+behaves more like other \s-1GNU\s0 programs.
+\s-1POSIX.2\s0 requires that options that follow file names must be
+treated as file names; by default, such options are permuted to the
+front of the operand list and are treated as options.
+Also, \s-1POSIX.2\s0 requires that unrecognized options be diagnosed as
+\*(lqillegal\*(rq, but since they are not really against the law the default
+is to diagnose them as \*(lqinvalid\*(rq.
+.B POSIXLY_CORRECT
+also disables \fB_\fP\fIN\fP\fB_GNU_nonoption_argv_flags_\fP,
+described below.
+.TP
+\fB_\fP\fIN\fP\fB_GNU_nonoption_argv_flags_\fP
+(Here
+.I N
+is
+.BR grep 's
+numeric process ID.) If the
+.IR i th
+character of this environment variable's value is
+.BR 1 ,
+do not consider the
+.IR i th
+operand of
+.B grep
+to be an option, even if it appears to be one.
+A shell can put this variable in the environment for each command it runs,
+specifying which operands are the results of file name wildcard
+expansion and therefore should not be treated as options.
+This behavior is available only with the \s-1GNU\s0 C library, and only
+when
+.B POSIXLY_CORRECT
+is not set.
.SH DIAGNOSTICS
.PP
Normally, exit status is 0 if matches were found,
OpenPOWER on IntegriCloud