1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-15 10:17:20 +00:00

Virgin import of a trimmed down GNU Grep 2.3.

It is being re-imported here, to keep our long source change history with
this source continuous.
src/contrib/grep will be deleted some time in the very near future.
This commit is contained in:
David E. O'Brien 1999-11-21 01:50:08 +00:00
parent c0e0ea0037
commit 678b4e4854
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/vendor/misc-GNU/dist1/; revision=53480

View File

@ -1,24 +1,24 @@
.TH GREP 1 "1992 September 10" "GNU Project"
.\" grep man page
.de Id
.ds Dt \\$4
..
.Id $Id: grep.1,v 1.1 1998/11/22 06:45:20 alainm Exp $
.TH GREP 1 \*(Dt "GNU Project"
.SH NAME
grep, egrep, fgrep \- print lines matching a pattern
.SH SYNOPOSIS
.SH SYNOPSIS
.B grep
[
.BR \- [[ AB "] ]\c"
.I "num"
]
[
.BR \- [ CEFGVBchilnsvwx ]
]
[
.B \-e
]
.I pattern
|
.BI \-f file
] [
[-[AB] NUM] [-CEFGVabchiLlnqrsvwxyUu] [-e PATTERN | -f FILE]
[-d ACTION] [--directories=ACTION]
[--extended-regexp] [--fixed-strings] [--basic-regexp]
[--regexp=PATTERN] [--file=FILE] [--ignore-case] [--word-regexp]
[--line-regexp] [--line-regexp] [--no-messages] [--revert-match]
[--version] [--help] [--byte-offset] [--line-number]
[--with-filename] [--no-filename] [--quiet] [--silent] [--text]
[--files-without-match] [--files-with-matcces] [--count]
[--before-context=NUM] [--after-context=NUM] [--context]
[--binary] [--unix-byte-offsets] [--recursive]
.I files...
]
.SH DESCRIPTION
.PP
.B Grep
@ -39,17 +39,17 @@ There are three major variants of
controlled by the following options.
.PD 0
.TP
.B \-G
.B \-G, --basic-regexp
Interpret
.I pattern
as a basic regular expression (see below). This is the default.
.TP
.B \-E
.B \-E, --extended-regexp
Interpret
.I pattern
as an extended regular expression (see below).
.TP
.B \-F
.B \-F, --fixed-strings
Interpret
.I pattern
as a list of fixed strings, separated by newlines,
@ -61,7 +61,7 @@ and
.B fgrep
are available.
.B Egrep
is similiar (but not identical) to
is similar (but not identical) to
.BR "grep\ \-E" ,
and is compatible with the historical Unix
.BR egrep .
@ -75,87 +75,157 @@ All variants of
understand the following options:
.PD 0
.TP
.BI \- num
Matches will be printed with
.I num
lines of leading and trailing context. However,
.BI \-A " NUM" ", --after-context=" NUM
Print
.I NUM
lines of trailing context after matching lines.
.TP
.BI \-B " NUM" ", --before-context=" NUM
Print
.I NUM
lines of leading context before matching lines.
.TP
.BI \-C ,\ --context"[=NUM]"
Print
.I NUM
lines (default 2) of output context.
.TP
.BI \- NUM \
Same as --context=NUM lines of leading and trailing context. However,
.B grep
will never print any given line more than once.
.TP
.BI \-A " num"
Print
.I num
lines of trailing context after matching lines.
.TP
.BI \-B " num"
Print
.I num
lines of leading context before matching lines.
.TP
.B \-C
Equivalent to
.BR \-2 .
.TP
.B \-V
.B \-V, --version
Print the version number of
.B grep
to standard error. This version number should
be included in all bug reports (see below).
.TP
.B \-b
.B \-b, --byte-offset
Print the byte offset within the input file before
each line of output.
.TP
.B \-c
.B \-c, --count
Suppress normal output; instead print a count of
matching lines for each input file.
With the
.B \-v
.B \-v, --revert-match
option (see below), count non-matching lines.
.TP
.BI \-e " pattern"
.BI \-d " ACTION" ", --directories=" ACTION
If an input file is a directory, use
.I ACTION
to process it. By default,
.I ACTION
is
.BR read ,
which means that directories are read just as if they were ordinary files.
If
.I ACTION
is
.BR skip ,
directories are silently skipped.
If
.I ACTION
is
.BR recurse ,
.B
grep reads all files under each directory, recursively;
this is equivalent to the
.B \-r
option.
.TP
.BI \-e " PATTERN" ", --regexp=" PATTERN
Use
.I pattern
.I PATTERN
as the pattern; useful to protect patterns beginning with
.BR \- .
.TP
.BI \-f " file"
Obtain the pattern from
.IR file .
.BI \-f " FILE" ", --file=" FILE
Obtain patterns from
.IR FILE ,
one per line.
The empty file contains zero patterns, and therfore matches nothing.
.TP
.B \-h
.B \-h, --no-filename
Suppress the prefixing of filenames on output
when multiple files are searched.
.TP
.B \-i
.B \-i, --ignore-case
Ignore case distinctions in both the
.I pattern
and the input files.
.TP
.B \-L
.B \-L, --files-without-match
Suppress normal output; instead print the name
of each input file from which no output would
normally have been printed.
normally have been printed. The scanning will stop
on the first match.
.TP
.B \-l
.B \-l, --files-with-matches
Suppress normal output; instead print
the name of each input file from which output
would normally have been printed.
would normally have been printed. The scanning will
stop on the first match.
.TP
.B \-n
.B \-n, --line-number
Prefix each line of output with the line number
within its input file.
.TP
.B \-q
Quiet; suppress normal output.
.TP
.B \-q, --quiet, --silent
Quiet; suppress normal output. The scanning will stop
on the first match.
Also see the
.B \-s
Suppress error messages about nonexistent or unreadable files.
or
.B --no-messages
option below.
.TP
.B \-v
.B \-r, --recursive
Read all files under each directory, recursively;
this is equivalent to the
.B "\-d recurse"
option.
.TP
.B \-s, --no-messages
Suppress error messages about nonexistent or unreadable files.
Portability note: unlike GNU
.BR grep ,
BSD
.B grep
does not comply with POSIX.2, because BSD
.B grep
lacks a
.B \-q
option and its
.B \-s
option behaves like GNU
.BR grep 's
.B \-q
option.
Shell scripts intended to be portable to BSD
.B grep
should avoid both
.B \-q
and
.B \-s
and should redirect output to /dev/null instead.
.TP
.B \-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,
.B grep
outputs only a message saying that the file matches the pattern.
This option causes
.B grep
to act as if the file is a text file,
even if it would otherwise be treated as binary.
.TP
.B \-v, --revert-match
Invert the sense of matching, to select non-matching lines.
.TP
.B \-w
.B \-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
@ -163,13 +233,46 @@ 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
.B \-x
.B \-x, --line-regexp
Select only those matches that exactly match the whole line.
.TP
.B \-y
Obsolete synonym for
.BR \-i .
.TP
.B \-U, --binary
Treat the file(s) as binary. By default, under MS-DOS and MS-Windows,
.BR grep
guesses the file type by looking at the contents of the first 32KB
read from the file. If
.BR grep
decides the file is a text file, it strips the CR characters from the
original file contents (to make regular expressions with
.B ^
and
.B $
work correctly). Specifying
.B \-U
overrules this guesswork, causing all files to be read and passed to the
matching mechanism verbatim; if the file is a text file with CR/LF
pairs at the end of each line, this will cause some regular
expressions to fail. This option is only supported on MS-DOS and
MS-Windows.
.TP
.B \-u, --unix-byte-offsets
Report Unix-style byte offsets. This switch causes
.B grep
to report byte offsets as if the file were Unix-style text file, i.e. with
CR characters stripped off. This will produce results identical to running
.B grep
on a Unix machine. This option has no effect unless
.B \-b
option is also used; it is only supported on MS-DOS and MS-Windows.
.PD
.SH "REGULAR EXPRESSIONS"
.PP
A regular expression is a pattern that describes a set of strings.
Regular expressions are constructed analagously to arithmetic
Regular expressions are constructed analogously to arithmetic
expressions, by using various operators to combine smaller expressions.
.PP
.B Grep
@ -216,7 +319,7 @@ Their names are self explanatory, and they are
.BR [:upper:] ,
and
.BR [:xdigit:].
For example,
For example,
.B [[:alnum:]]
means
.BR [0-9A-Za-z] ,
@ -265,8 +368,7 @@ matches the empty string provided it's
.I not
at the edge of a word.
.PP
A regular expression matching a single character may be followed
by one of several repetition operators:
A regular expression may be followed by one of several repetition operators:
.PD 0
.TP
.B ?
@ -360,7 +462,7 @@ other system errors.
.SH BUGS
.PP
Email bug reports to
.BR bug-gnu-utils@prep.ai.mit.edu .
.BR bug-gnu-utils@gnu.org .
Be sure to include the word ``grep'' somewhere in the ``Subject:'' field.
.PP
Large repetition counts in the