=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/grep/grep.1,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- src/usr.bin/grep/grep.1 2003/04/25 14:53:03 1.4 +++ src/usr.bin/grep/grep.1 2003/06/10 09:12:10 1.5 @@ -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 @@ .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 @@ .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 @@ .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 @@ 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 @@ 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 @@ .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 @@ .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