diff --git a/usr.bin/grep/grep.1 b/usr.bin/grep/grep.1 index f790ce1770a..b144d1033d7 100644 --- a/usr.bin/grep/grep.1 +++ b/usr.bin/grep/grep.1 @@ -30,7 +30,7 @@ .\" .\" @(#)grep.1 8.3 (Berkeley) 4/18/94 .\" -.Dd April 17, 2017 +.Dd May 26, 2017 .Dt GREP 1 .Os .Sh NAME @@ -40,7 +40,7 @@ .Sh SYNOPSIS .Nm grep .Bk -words -.Op Fl abcdDEFGHhIiJLlmnOopqRSsUVvwxZz +.Op Fl abcDdEFGHhIiJLlmnOopqRSsUVvwxZz .Op Fl A Ar num .Op Fl B Ar num .Op Fl C Ns Op Ar num @@ -48,10 +48,13 @@ .Op Fl f Ar file .Op Fl Fl binary-files Ns = Ns Ar value .Op Fl Fl color Ns Op = Ns Ar when -.Op Fl Fl colour Ns Op = Ns Ar when -.Op Fl Fl context Ns Op = Ns Ar num -.Op Fl Fl label +.Op Fl Fl exclude Ns = Ns Ar pattern +.Op Fl Fl exclude-dir Ns = Ns Ar pattern +.Op Fl Fl include Ns = Ns Ar pattern +.Op Fl Fl include-dir Ns = Ns Ar pattern +.Op Fl Fl label Ns = Ns Ar value .Op Fl Fl line-buffered +.Op Fl Fl mmap .Op Fl Fl null .Op Ar pattern .Op Ar @@ -136,7 +139,17 @@ options. .It Fl b , Fl Fl byte-offset The offset in bytes of a matched pattern is displayed in front of the respective matched line. -.It Fl C Ns Op Ar num , Fl Fl context Ns = Ns Ar num +.It Fl Fl binary-files Ns = Ns Ar value +Controls searching and printing of binary files. +Options are +.Ar binary , +the default: search binary files but do not print them; +.Ar without-match : +do not search binary files; +and +.Ar text : +treat all files as text. +.It Fl C Ns Oo Ar num Oc , Fl Fl context Ns Oo = Ns Ar num Oc Print .Ar num lines of leading and trailing context surrounding each match. @@ -149,7 +162,7 @@ Note: no whitespace may be given between the option and its argument. .It Fl c , Fl Fl count Only a count of selected lines is written to standard output. -.It Fl Fl colour Ns = Ns Op Ar when , Fl Fl color Ns = Ns Op Ar when +.It Fl Fl color Ns Oo = Ns Ar when Oc , Fl Fl colour Ns Oo = Ns Ar when Oc Mark up the matching text with the expression stored in .Ev GREP_COLOR environment variable. @@ -295,6 +308,14 @@ Pathnames are listed once per file searched. If the standard input is searched, the string .Dq (standard input) is written. +.It Fl Fl label Ns = Ns Ar value +When reading from standard input, display +.Ar value +as file name. +.It Fl Fl line-buffered +Force output to be line buffered. +By default, output is line buffered when standard output is a terminal +and block buffered otherwise. .It Fl Fl mmap Use .Xr mmap 2 @@ -386,27 +407,6 @@ Force .Nm grep to behave as .Nm zgrep . -.It Fl Fl binary-files Ns = Ns Ar value -Controls searching and printing of binary files. -Options are -.Ar binary , -the default: search binary files but do not print them; -.Ar without-match : -do not search binary files; -and -.Ar text : -treat all files as text. -.Sm off -.It Fl Fl context Op = Ar num -.Sm on -Print -.Ar num -lines of leading and trailing context. -The default is 2. -.It Fl Fl line-buffered -Force output to be line buffered. -By default, output is line buffered when standard output is a terminal -and block buffered otherwise. .El .Pp If no file arguments are specified, the standard input is used. @@ -476,7 +476,7 @@ utility is compliant with the specification. .Pp The flags -.Op Fl AaBbCDdGHhIJLmoPRSUVwZ +.Op Fl AaBbCDdGHhIJLmopRSUVwZ are extensions to that specification, and the behaviour of the .Fl f flag when used with an empty pattern file is left undefined. diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c index e6eaf4b0c6c..6eb85acc4cf 100644 --- a/usr.bin/grep/grep.c +++ b/usr.bin/grep/grep.c @@ -68,9 +68,10 @@ const char *errstr[] = { /* 1*/ "(standard input)", /* 2*/ "cannot read bzip2 compressed file", /* 3*/ "unknown %s option", -/* 4*/ "usage: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZz] [-A num] [-B num] [-C[num]]\n", -/* 5*/ "\t[-e pattern] [-f file] [--binary-files=value] [--color=when]\n", -/* 6*/ "\t[--context[=num]] [--directories=action] [--label] [--line-buffered]\n", +/* 4*/ "usage: %s [-abcDEFGHhIiJLlmnOopqRSsUVvwxZz] [-A num] [-B num] [-C[num]]\n", +/* 5*/ "\t[-e pattern] [-f file] [--binary-files=value] [--color[=when]]\n" + "\t[--exclude=pattern] [--exclude-dir=pattern] [--include=pattern]\n", +/* 6*/ "\t[--include-dir=pattern] [--label=value] [--line-buffered] [--mmap]\n", /* 7*/ "\t[--null] [pattern] [file ...]\n", /* 8*/ "Binary file %s matches\n", /* 9*/ "%s (BSD grep) %s\n", @@ -174,7 +175,8 @@ usage(void) exit(2); } -static const char *optstr = "0123456789A:B:C:D:EFGHIJMLOPSRUVZabcd:e:f:hilm:nopqrsuvwxXyz"; +static const char *optstr = + "0123456789A:B:C:D:EFGHIJMLOSRUVZabcd:e:f:hilm:nopqrsuvwxXyz"; static const struct option long_options[] = { @@ -197,7 +199,7 @@ static const struct option long_options[] = {"context", optional_argument, NULL, 'C'}, {"count", no_argument, NULL, 'c'}, {"devices", required_argument, NULL, 'D'}, - {"directories", required_argument, NULL, 'd'}, + {"directories", required_argument, NULL, 'd'}, {"extended-regexp", no_argument, NULL, 'E'}, {"regexp", required_argument, NULL, 'e'}, {"fixed-strings", no_argument, NULL, 'F'},