summaryrefslogtreecommitdiff
path: root/usr.bin/grep
diff options
context:
space:
mode:
authorJason McIntyre <jmc@cvs.openbsd.org>2003-06-10 09:12:14 +0000
committerJason McIntyre <jmc@cvs.openbsd.org>2003-06-10 09:12:14 +0000
commit954f7917cd61e2c4e87fa97f77b5d16372fced8d (patch)
tree871a313e9494c2e181e8b7547436ca52ed2b21b5 /usr.bin/grep
parent7da7265de4dc122cf4762c2707b245904c8acdd7 (diff)
- section reorder
- COMPATIBILITY merge - macro cleanup - kill whitespace at EOL - new sentence, new line ssh pages ok markus@
Diffstat (limited to 'usr.bin/grep')
-rw-r--r--usr.bin/grep/grep.1120
1 files changed, 64 insertions, 56 deletions
diff --git a/usr.bin/grep/grep.1 b/usr.bin/grep/grep.1
index 3e8af4e6410..6713a560f12 100644
--- a/usr.bin/grep/grep.1
+++ b/usr.bin/grep/grep.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: grep.1,v 1.4 2003/04/25 14:53:03 jmc Exp $
+.\" $OpenBSD: grep.1,v 1.5 2003/06/10 09:12:10 jmc Exp $
.\"
.\" Copyright (c) 2000 Carson Harding. All rights reserved.
.\" This code was written and contributed to OpenBSD by Carson Harding.
@@ -11,7 +11,7 @@
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
-.\" 3. Neither the name of the author, or the names of contributors may be
+.\" 3. Neither the name of the author, or the names of contributors may be
.\" used to endorse or promote products derived from this software without
.\" specific prior written permission.
.\"
@@ -35,6 +35,7 @@
.Nd print lines matching a pattern
.Sh SYNOPSIS
.Nm grep
+.Bk -words
.Op Fl E | Fl F
.Op Fl bchilnqsvwxz
.Oo
@@ -46,14 +47,16 @@
.Op Ar pattern
.Op Ar file
.Ar ...
+.Ek
.Sh DESCRIPTION
The
.Nm
-utility searches for lines that contain the specified pattern
-or patterns. By default
+utility searches for lines that contain the specified pattern
+or patterns.
+By default
.Nm
-prints lines containing matches to the standard output. If no input files
-are specified,
+prints lines containing matches to the standard output.
+If no input files are specified,
.Nm
expects to read its input from the standard input.
.Pp
@@ -68,39 +71,40 @@ is equivalent to
.Pp
The patterns are regular expressions, or in the case of
.Nm fgrep ,
-fixed strings. More than one pattern may be specified on the
-command-line, either by repeated use of the
+fixed strings.
+More than one pattern may be specified on the command-line,
+either by repeated use of the
.Fl e
flag, or by separating patterns with newlines:
-
-.Nm grep
-\'Ishmael
- Ahab' mobydick.txt
-
+.Pp
+.Bd -literal -offset indent
+grep \'Ishmael
+Ahab' mobydick.txt
+.Ed
+.Pp
is the same as:
-
-.Nm
--e Ishmael -e Ahab mobydick.txt
-
+.Pp
+.Dl grep -e Ishmael -e Ahab mobydick.txt
+.Pp
Note that many regular expression special characters also have special
-meaning to the shell. It is best to enclose the regular expression
-in quotation marks. Note also that a null pattern ("" or a newline alone)
-matches all input.
+meaning to the shell.
+It is best to enclose the regular expression in quotation marks.
+Note also that a null pattern ("" or a newline alone) matches all input.
.Sh OPTIONS
-.Pp
The options available are:
.Bl -tag -width file Ds
.It Fl E
Use extended regular expressions, as if the program was invoked as
-.Nm egrep.
+.Nm egrep .
.It Fl F
Patterns are fixed strings, not regular expressions, as if the
program was invoked as
-.Nm fgrep.
+.Nm fgrep .
.It Fl a
-Does nothing. In other greps this flag tells grep to treat the input
-as ASCII and turns off attempts to determine whether the input file is a
-binary file. This
+Does nothing.
+In other greps this flag tells grep to treat the input as ASCII and turns off
+attempts to determine whether the input file is a binary file.
+This
.Nm grep
does not (yet) do that check, so behaves as if
.Fl a
@@ -110,9 +114,9 @@ Prepend the byte-offset of the beginning of the line containing the match.
.It Fl c
Print only a count of the matches found.
.It Fl e Ar pattern_list
-The argument to
+The argument to
.Fl e
-is a list of patterns to search for.
+is a list of patterns to search for.
.Fl e
may be used multiple times, each instance of which may have
one or more patterns separated by new-lines.
@@ -133,46 +137,52 @@ If the input is the standard input,
.Nm
prints "(standard input)".
.It Fl n
-Prefix matching lines with their line number in the file in which
+Prefix matching lines with their line number in the file in which
they occur.
.It Fl q
Be quiet about errors accessing files, only return program status.
The status returned is 0 if there was a match, 1 if there were no
-matches, even if there were errors accessing files. (Without the
+matches, even if there were errors accessing files.
+(Without the
.Fl q
-flag, if there was an error
-accessing a file
+flag, if there was an error
+accessing a file
.Nm
would return a status of 2 even
if it found matches.)
.It Fl s
-Suppress errors about accessing files. Note that unlike
+Suppress errors about accessing files.
+Note that unlike
.Fl q
the program is not quiet: matches are still output.
.It Fl v
Invert the sense of the match: return all lines that do not
contain the pattern.
.It Fl w
-The pattern is considered a word. A matching pattern in a line must not
-be immediately bordered by a letter, a number, or an underscore ('_').
+The pattern is considered a word.
+A matching pattern in a line must not be immediately bordered by a letter,
+a number, or an underscore ('_').
.It Fl x
-Match the line exactly. If a regular expression (invoked as
+Match the line exactly.
+If a regular expression (invoked as
.Nm grep ,
or
.Nm egrep )
the pattern must match the whole line (as if
-the pattern was enclosed in ^ and $). If invoked as
-.Nm fgrep,
+the pattern was enclosed in ^ and $).
+If invoked as
+.Nm fgrep ,
the string must match the entire line.
.It Fl z
When the
.Fl l
flag is also specified, print an ASCII NUL character (0) following
-the file name, rather than a newline. Like the
+the file name, rather than a newline.
+Like the
.Fl print0
option to
.Nm find ,
-this may be used to pass file names containing unusual characters
+this may be used to pass file names containing unusual characters
to programs such as
.Nm xargs
with the
@@ -180,40 +190,38 @@ with the
flag.
.El
.Sh FILESYSTEM TRAVERSAL OPTIONS
-.Pp
The following options control recursive searchs:
.Bl -tag -width file Ds
.It Fl R
Recursively descend through any specified directory arguments.
.It Fl H
-If the
-.Fl R
+If the
+.Fl R
option is also specified, symbolic links on the command
-line are followed. (Symbolic links encountered in the tree
-traversal are not followed.)
+line are followed.
+(Symbolic links encountered in the tree traversal are not followed.)
.It Fl L
If the
.Fl R
option is also specified, all symbolic links are followed.
.It Fl P
-If the
+If the
.Fl R
option is also specified, no symbolic links are followed.
.It Fl X
-If the
-.Fl R
+If the
+.Fl R
option is also specified, searches are confined to the device on
which the search started (file system mount points are not crossed).
.El
.Sh EXAMPLES
-.Pp
To print all occurrences of the word Ishmael in mobydick.txt:
.Dl grep Ishmael mobydick.txt
.Pp
To merely count all the lines in which the word Ishmael occurs:
.Dl grep -c Ishmael mobydick.txt
.Pp
-To print all occurrences of either of the words Ishmael or Ahab in
+To print all occurrences of either of the words Ishmael or Ahab in
mobydick.txt:
.Dl grep 'Ishmael|Ahab' mobydick.txt
.Pp
@@ -225,7 +233,6 @@ of a compound:
To find all the empty lines and print the line numbers for where they occur:
.Dl grep -nv \&. mobydick.txt
.Sh DIAGNOSTICS
-.Pp
The
.Nm
utility exits with one of the following values:
@@ -240,11 +247,12 @@ An error occurred (whether or not matches were found).
.El
.Pp
Note that when the
-.Fl q
-flag is used, file access errors do not cause an exit value of 2,
+.Fl q
+flag is used, file access errors do not cause an exit value of 2,
and in the absence of other errors (a bad regular expression)
the exit value is determined only by whether or not matches
-were found. (XX Should -s do the same??)
+were found.
+(XX Should -s do the same??)
.Sh SEE ALSO
.Xr regex 3 ,
.Xr re_format 7
@@ -253,8 +261,8 @@ A
.Nm grep
command appeared in
.At v6 .
-This version is a re-implementation from the POSIX specification and
-inspection of the operation of several implementations of
+This version is a re-implementation from the POSIX specification and
+inspection of the operation of several implementations of
.Nm grep .
.Sh NOTES
.Nm grep