grep(1): Upgrade version 2.20 => 2.22
[dragonfly.git] / gnu / usr.bin / grep / grep / grep.1
1 .\" GNU grep man page
2 .if !\n(.g \{\
3 .       if !\w|\*(lq| \{\
4 .               ds lq ``
5 .               if \w'\(lq' .ds lq "\(lq
6 .       \}
7 .       if !\w|\*(rq| \{\
8 .               ds rq ''
9 .               if \w'\(rq' .ds rq "\(rq
10 .       \}
11 .\}
12 .
13 .ie \n[.g] .mso www.tmac
14 .el \{\
15 . de MTO
16 \\$2 \(laemail: \\$1 \(ra\\$3
17 ..
18 . de URL
19 \\$2 \(laURL: \\$1 \(ra\\$3
20 ..
21 .\}
22 .
23 .TH GREP 1 \*(Dt "GNU grep 2.22" "User Commands"
24 .hy 0
25 .
26 .SH NAME
27 grep, egrep, fgrep \- print lines matching a pattern
28 .
29 .SH SYNOPSIS
30 .B grep
31 .RI [ OPTIONS ]
32 .I PATTERN
33 .RI [ FILE .\|.\|.]
34 .br
35 .B grep
36 .RI [ OPTIONS ]
37 .RB [ \-e
38 .I PATTERN
39 |
40 .B \-f
41 .IR FILE ]
42 .RI [ FILE .\|.\|.]
43 .
44 .SH DESCRIPTION
45 .B grep
46 searches the named input
47 .IR FILE s
48 for lines containing a match to the given
49 .IR PATTERN .
50 If no files are specified, or if the file
51 .RB "\*(lq" \- "\*(rq"
52 is given,
53 .B grep
54 searches standard input.
55 By default,
56 .B grep
57 prints the matching lines.
58 .PP
59 In addition, the variant programs
60 .B egrep
61 and
62 .B fgrep
63 are the same as
64 .B "grep\ \-E"
65 and
66 .BR "grep\ \-F" ,
67 respectively.
68 These variants are deprecated, but are provided for backward compatibility.
69 .
70 .SH OPTIONS
71 .SS "Generic Program Information"
72 .TP
73 .B \-\^\-help
74 Output a usage message and exit.
75 .TP
76 .BR \-V ", " \-\^\-version
77 Output the version number of
78 .B grep
79 and exit.
80 .SS "Matcher Selection"
81 .TP
82 .BR \-E ", " \-\^\-extended\-regexp
83 Interpret
84 .I PATTERN
85 as an extended regular expression (ERE, see below).
86 .TP
87 .BR \-F ", " \-\^\-fixed\-strings
88 Interpret
89 .I PATTERN
90 as a list of fixed strings, separated by newlines,
91 any of which is to be matched.
92 .TP
93 .BR \-G ", " \-\^\-basic\-regexp
94 Interpret
95 .I PATTERN
96 as a basic regular expression (BRE, see below).
97 This is the default.
98 .TP
99 .BR \-P ", " \-\^\-perl\-regexp
100 Interpret
101 .I PATTERN
102 as a Perl regular expression.
103 This is highly experimental and
104 .B "grep \-P"
105 may warn of unimplemented features.
106 .SS "Matching Control"
107 .TP
108 .BI \-e " PATTERN" "\fR,\fP \-\^\-regexp=" PATTERN
109 Use
110 .I PATTERN
111 as the pattern.
112 This can be used to specify multiple search patterns,
113 or to protect a pattern beginning with a hyphen
114 .RB ( \- ).
115 .TP
116 .BI \-f " FILE" "\fR,\fP \-\^\-file=" FILE
117 Obtain patterns from
118 .IR FILE ,
119 one per line.
120 The empty file contains zero patterns, and therefore matches nothing.
121 .TP
122 .BR \-i ", " \-\^\-ignore\-case
123 Ignore case distinctions in both the
124 .I PATTERN
125 and the input files.
126 .TP
127 .BR \-v ", " \-\^\-invert\-match
128 Invert the sense of matching, to select non-matching lines.
129 .TP
130 .BR \-w ", " \-\^\-word\-regexp
131 Select only those lines containing matches that form whole words.
132 The test is that the matching substring must either be at the
133 beginning of the line, or preceded by a non-word constituent
134 character.
135 Similarly, it must be either at the end of the line
136 or followed by a non-word constituent character.
137 Word-constituent characters are letters, digits, and the underscore.
138 .TP
139 .BR \-x ", " \-\^\-line\-regexp
140 Select only those matches that exactly match the whole line.
141 .TP
142 .B \-y
143 Obsolete synonym for
144 .BR \-i .
145 .SS "General Output Control"
146 .TP
147 .BR \-c ", " \-\^\-count
148 Suppress normal output; instead print a count of
149 matching lines for each input file.
150 With the
151 .BR \-v ", " \-\^\-invert\-match
152 option (see below), count non-matching lines.
153 .TP
154 .BR \-\^\-color [ =\fIWHEN\fP "], " \-\^\-colour [ =\fIWHEN\fP ]
155 Surround the matched (non-empty) strings, matching lines, context lines,
156 file names, line numbers, byte offsets, and separators (for fields and
157 groups of context lines) with escape sequences to display them in color
158 on the terminal.
159 The colors are defined by the environment variable
160 .BR GREP_COLORS .
161 The deprecated environment variable
162 .B GREP_COLOR
163 is still supported, but its setting does not have priority.
164 .I WHEN
165 is
166 .BR never ", " always ", or " auto .
167 .TP
168 .BR \-L ", " \-\^\-files\-without\-match
169 Suppress normal output; instead print the name
170 of each input file from which no output would
171 normally have been printed.
172 The scanning will stop on the first match.
173 .TP
174 .BR \-l ", " \-\^\-files\-with\-matches
175 Suppress normal output; instead print
176 the name of each input file from which output
177 would normally have been printed.
178 The scanning will stop on the first match.
179 .TP
180 .BI \-m " NUM" "\fR,\fP \-\^\-max\-count=" NUM
181 Stop reading a file after
182 .I NUM
183 matching lines.
184 If the input is standard input from a regular file,
185 and
186 .I NUM
187 matching lines are output,
188 .B grep
189 ensures that the standard input is positioned to just after the last
190 matching line before exiting, regardless of the presence of trailing
191 context lines.
192 This enables a calling process to resume a search.
193 When
194 .B grep
195 stops after
196 .I NUM
197 matching lines, it outputs any trailing context lines.
198 When the
199 .B \-c
200 or
201 .B \-\^\-count
202 option is also used,
203 .B grep
204 does not output a count greater than
205 .IR NUM .
206 When the
207 .B \-v
208 or
209 .B \-\^\-invert\-match
210 option is also used,
211 .B grep
212 stops after outputting
213 .I NUM
214 non-matching lines.
215 .TP
216 .BR \-o ", " \-\^\-only\-matching
217 Print only the matched (non-empty) parts of a matching line,
218 with each such part on a separate output line.
219 .TP
220 .BR \-q ", " \-\^\-quiet ", " \-\^\-silent
221 Quiet; do not write anything to standard output.
222 Exit immediately with zero status if any match is found,
223 even if an error was detected.
224 Also see the
225 .B \-s
226 or
227 .B \-\^\-no\-messages
228 option.
229 .TP
230 .BR \-s ", " \-\^\-no\-messages
231 Suppress error messages about nonexistent or unreadable files.
232 .SS "Output Line Prefix Control"
233 .TP
234 .BR \-b ", " \-\^\-byte\-offset
235 Print the 0-based byte offset within the input file
236 before each line of output.
237 If
238 .B \-o
239 .RB ( \-\^\-only\-matching )
240 is specified,
241 print the offset of the matching part itself.
242 .TP
243 .BR \-H ", " \-\^\-with\-filename
244 Print the file name for each match.
245 This is the default when there is more than one file to search.
246 .TP
247 .BR \-h ", " \-\^\-no\-filename
248 Suppress the prefixing of file names on output.
249 This is the default when there is only one file
250 (or only standard input) to search.
251 .TP
252 .BI \-\^\-label= LABEL
253 Display input actually coming from standard input as input coming from file
254 .IR LABEL .
255 This is especially useful when implementing tools like
256 .BR zgrep ,
257 e.g.,
258 .BR "gzip -cd foo.gz | grep --label=foo -H something" .
259 See also the
260 .B \-H
261 option.
262 .TP
263 .BR \-n ", " \-\^\-line\-number
264 Prefix each line of output with the 1-based line number
265 within its input file.
266 .TP
267 .BR \-T ", " \-\^\-initial\-tab
268 Make sure that the first character of actual line content lies on a
269 tab stop, so that the alignment of tabs looks normal.
270 This is useful with options that prefix their output to the actual content:
271 .BR \-H , \-n ,
272 and
273 .BR \-b .
274 In order to improve the probability that lines
275 from a single file will all start at the same column,
276 this also causes the line number and byte offset (if present)
277 to be printed in a minimum size field width.
278 .TP
279 .BR \-u ", " \-\^\-unix\-byte\-offsets
280 Report Unix-style byte offsets.
281 This switch causes
282 .B grep
283 to report byte offsets as if the file were a Unix-style text file,
284 i.e., with CR characters stripped off.
285 This will produce results identical to running
286 .B grep
287 on a Unix machine.
288 This option has no effect unless
289 .B \-b
290 option is also used;
291 it has no effect on platforms other than \s-1MS-DOS\s0 and \s-1MS\s0-Windows.
292 .TP
293 .BR \-Z ", " \-\^\-null
294 Output a zero byte (the \s-1ASCII\s0
295 .B NUL
296 character) instead of the character that normally follows a file name.
297 For example,
298 .B "grep \-lZ"
299 outputs a zero byte after each file name instead of the usual newline.
300 This option makes the output unambiguous, even in the presence of file
301 names containing unusual characters like newlines.
302 This option can be used with commands like
303 .BR "find \-print0" ,
304 .BR "perl \-0" ,
305 .BR "sort \-z" ,
306 and
307 .B "xargs \-0"
308 to process arbitrary file names,
309 even those that contain newline characters.
310 .SS "Context Line Control"
311 .TP
312 .BI \-A " NUM" "\fR,\fP \-\^\-after\-context=" NUM
313 Print
314 .I NUM
315 lines of trailing context after matching lines.
316 Places a line containing a group separator
317 .RB ( \-\^\- )
318 between contiguous groups of matches.
319 With the
320 .B \-o
321 or
322 .B \-\^\-only\-matching
323 option, this has no effect and a warning is given.
324 .TP
325 .BI \-B " NUM" "\fR,\fP \-\^\-before\-context=" NUM
326 Print
327 .I NUM
328 lines of leading context before matching lines.
329 Places a line containing a group separator
330 .RB ( \-\^\- )
331 between contiguous groups of matches.
332 With the
333 .B \-o
334 or
335 .B \-\^\-only\-matching
336 option, this has no effect and a warning is given.
337 .TP
338 .BI \-C " NUM" "\fR,\fP \-" NUM "\fR,\fP \-\^\-context=" NUM
339 Print
340 .I NUM
341 lines of output context.
342 Places a line containing a group separator
343 .RB ( \-\^\- )
344 between contiguous groups of matches.
345 With the
346 .B \-o
347 or
348 .B \-\^\-only\-matching
349 option, this has no effect and a warning is given.
350 .SS "File and Directory Selection"
351 .TP
352 .BR \-a ", " \-\^\-text
353 Process a binary file as if it were text; this is equivalent to the
354 .B \-\^\-binary\-files=text
355 option.
356 .TP
357 .BI \-\^\-binary\-files= TYPE
358 If the first few bytes of a file indicate that the file contains binary
359 data, assume that the file is of type
360 .IR TYPE .
361 By default,
362 .I TYPE
363 is
364 .BR binary ,
365 and
366 .B grep
367 normally outputs either
368 a one-line message saying that a binary file matches, or no message if
369 there is no match.
370 If
371 .I TYPE
372 is
373 .BR without-match ,
374 .B grep
375 assumes that a binary file does not match; this is equivalent to the
376 .B \-I
377 option.
378 If
379 .I TYPE
380 is
381 .BR text ,
382 .B grep
383 processes a binary file as if it were text; this is equivalent to the
384 .B \-a
385 option.
386 When processing binary data,
387 .B grep
388 may treat non-text bytes as line terminators; for example, the pattern
389 .RB ' . '\&
390 (period) might not match a null byte, as the null byte might be
391 treated as a line terminator.
392 .I Warning:
393 .B "grep \-\^\-binary\-files=text"
394 might output binary garbage,
395 which can have nasty side effects if the output is a terminal and if the
396 terminal driver interprets some of it as commands.
397 .TP
398 .BI \-D " ACTION" "\fR,\fP \-\^\-devices=" ACTION
399 If an input file is a device, FIFO or socket, use
400 .I ACTION
401 to process it.
402 By default,
403 .I ACTION
404 is
405 .BR read ,
406 which means that devices are read just as if they were ordinary files.
407 If
408 .I ACTION
409 is
410 .BR skip ,
411 devices are silently skipped.
412 .TP
413 .BI \-d " ACTION" "\fR,\fP \-\^\-directories=" ACTION
414 If an input file is a directory, use
415 .I ACTION
416 to process it.
417 By default,
418 .I ACTION
419 is
420 .BR read ,
421 i.e., read directories just as if they were ordinary files.
422 If
423 .I ACTION
424 is
425 .BR skip ,
426 silently skip directories.
427 If
428 .I ACTION
429 is
430 .BR recurse ,
431 read all files under each directory, recursively,
432 following symbolic links only if they are on the command line.
433 This is equivalent to the
434 .B \-r
435 option.
436 .TP
437 .BI \-\^\-exclude= GLOB
438 Skip files whose base name matches
439 .I GLOB
440 (using wildcard matching).
441 A file-name glob can use
442 .BR * ,
443 .BR ? ,
444 and
445 .BR [ ... ]
446 as wildcards, and
447 .B \e
448 to quote a wildcard or backslash character literally.
449 .TP
450 .BI \-\^\-exclude-from= FILE
451 Skip files whose base name matches any of the file-name globs read from
452 .I FILE
453 (using wildcard matching as described under
454 .BR \-\^\-exclude ).
455 .TP
456 .BI \-\^\-exclude-dir= DIR
457 Exclude directories matching the pattern
458 .I DIR
459 from recursive searches.
460 .TP
461 .BR \-I
462 Process a binary file as if it did not contain matching data; this is
463 equivalent to the
464 .B \-\^\-binary\-files=without-match
465 option.
466 .TP
467 .BI \-\^\-include= GLOB
468 Search only files whose base name matches
469 .I GLOB
470 (using wildcard matching as described under
471 .BR \-\^\-exclude ).
472 .TP
473 .BR \-r ", " \-\^\-recursive
474 Read all files under each directory, recursively,
475 following symbolic links only if they are on the command line.
476 Note that if no file operand is given, grep searches the working directory.
477 This is equivalent to the
478 .B "\-d recurse"
479 option.
480 .TP
481 .BR \-R ", " \-\^\-dereference\-recursive
482 Read all files under each directory, recursively.
483 Follow all symbolic links, unlike
484 .BR \-r .
485 .SS "Other Options"
486 .TP
487 .BR \-\^\-line\-buffered
488 Use line buffering on output.
489 This can cause a performance penalty.
490 .TP
491 .BR \-U ", " \-\^\-binary
492 Treat the file(s) as binary.
493 By default, under \s-1MS-DOS\s0 and \s-1MS\s0-Windows,
494 .BR grep
495 guesses the file type by looking at the contents of the first 32KB
496 read from the file.
497 If
498 .BR grep
499 decides the file is a text file, it strips the CR characters from the
500 original file contents (to make regular expressions with
501 .B ^
502 and
503 .B $
504 work correctly).
505 Specifying
506 .B \-U
507 overrules this guesswork, causing all files to be read and passed to the
508 matching mechanism verbatim; if the file is a text file with CR/LF
509 pairs at the end of each line, this will cause some regular
510 expressions to fail.
511 This option has no effect on platforms
512 other than \s-1MS-DOS\s0 and \s-1MS\s0-Windows.
513 .TP
514 .BR \-z ", " \-\^\-null\-data
515 Treat the input as a set of lines,
516 each terminated by a zero byte (the \s-1ASCII\s0
517 .B NUL
518 character) instead of a newline.
519 Like the
520 .B -Z
521 or
522 .B \-\^\-null
523 option, this option can be used with commands like
524 .B sort -z
525 to process arbitrary file names.
526 .
527 .SH "REGULAR EXPRESSIONS"
528 A regular expression is a pattern that describes a set of strings.
529 Regular expressions are constructed analogously to arithmetic
530 expressions, by using various operators to combine smaller expressions.
531 .PP
532 .B grep
533 understands three different versions of regular expression syntax:
534 \*(lqbasic,\*(rq \*(lqextended\*(rq and \*(lqperl.\*(rq In
535 .RB "\s-1GNU\s0\ " grep ,
536 there is no difference in available functionality between basic and
537 extended syntaxes.
538 In other implementations, basic regular expressions are less powerful.
539 The following description applies to extended regular expressions;
540 differences for basic regular expressions are summarized afterwards.
541 Perl regular expressions give additional functionality, and are
542 documented in pcresyntax(3) and pcrepattern(3), but may not be
543 available on every system.
544 .PP
545 The fundamental building blocks are the regular expressions
546 that match a single character.
547 Most characters, including all letters and digits,
548 are regular expressions that match themselves.
549 Any meta-character with special meaning
550 may be quoted by preceding it with a backslash.
551 .PP
552 The period
553 .B .\&
554 matches any single character.
555 .SS "Character Classes and Bracket Expressions"
556 A
557 .I "bracket expression"
558 is a list of characters enclosed by
559 .B [
560 and
561 .BR ] .
562 It matches any single
563 character in that list; if the first character of the list
564 is the caret
565 .B ^
566 then it matches any character
567 .I not
568 in the list.
569 For example, the regular expression
570 .B [0123456789]
571 matches any single digit.
572 .PP
573 Within a bracket expression, a
574 .I "range expression"
575 consists of two characters separated by a hyphen.
576 It matches any single character that sorts between the two characters,
577 inclusive, using the locale's collating sequence and character set.
578 For example, in the default C locale,
579 .B [a\-d]
580 is equivalent to
581 .BR [abcd] .
582 Many locales sort characters in dictionary order, and in these locales
583 .B [a\-d]
584 is typically not equivalent to
585 .BR [abcd] ;
586 it might be equivalent to
587 .BR [aBbCcDd] ,
588 for example.
589 To obtain the traditional interpretation of bracket expressions,
590 you can use the C locale by setting the
591 .B LC_ALL
592 environment variable to the value
593 .BR C .
594 .PP
595 Finally, certain named classes of characters are predefined within
596 bracket expressions, as follows.
597 Their names are self explanatory, and they are
598 .BR [:alnum:] ,
599 .BR [:alpha:] ,
600 .BR [:cntrl:] ,
601 .BR [:digit:] ,
602 .BR [:graph:] ,
603 .BR [:lower:] ,
604 .BR [:print:] ,
605 .BR [:punct:] ,
606 .BR [:space:] ,
607 .BR [:upper:] ,
608 and
609 .BR [:xdigit:].
610 For example,
611 .B [[:alnum:]]
612 means the character class of numbers and
613 letters in the current locale. In the C locale and \s-1ASCII\s0
614 character set encoding, this is the same as
615 .BR [0\-9A\-Za\-z] .
616 (Note that the brackets in these class names are part of the symbolic
617 names, and must be included in addition to the brackets delimiting
618 the bracket expression.)
619 Most meta-characters lose their special meaning inside bracket expressions.
620 To include a literal
621 .B ]
622 place it first in the list.
623 Similarly, to include a literal
624 .B ^
625 place it anywhere but first.
626 Finally, to include a literal
627 .B \-
628 place it last.
629 .SS Anchoring
630 The caret
631 .B ^
632 and the dollar sign
633 .B $
634 are meta-characters that respectively match the empty string at the
635 beginning and end of a line.
636 .SS "The Backslash Character and Special Expressions"
637 The symbols
638 .B \e<
639 and
640 .B \e>
641 respectively match the empty string at the beginning and end of a word.
642 The symbol
643 .B \eb
644 matches the empty string at the edge of a word,
645 and
646 .B \eB
647 matches the empty string provided it's
648 .I not
649 at the edge of a word.
650 The symbol
651 .B \ew
652 is a synonym for
653 .B [_[:alnum:]]
654 and
655 .B \eW
656 is a synonym for
657 .BR [^_[:alnum:]] .
658 .SS Repetition
659 A regular expression may be followed by one of several repetition operators:
660 .PD 0
661 .TP
662 .B ?
663 The preceding item is optional and matched at most once.
664 .TP
665 .B *
666 The preceding item will be matched zero or more times.
667 .TP
668 .B +
669 The preceding item will be matched one or more times.
670 .TP
671 .BI { n }
672 The preceding item is matched exactly
673 .I n
674 times.
675 .TP
676 .BI { n ,}
677 The preceding item is matched
678 .I n
679 or more times.
680 .TP
681 .BI {, m }
682 The preceding item is matched at most
683 .I m
684 times.
685 This is a \s-1GNU\s0 extension.
686 .TP
687 .BI { n , m }
688 The preceding item is matched at least
689 .I n
690 times, but not more than
691 .I m
692 times.
693 .PD
694 .SS Concatenation
695 Two regular expressions may be concatenated; the resulting
696 regular expression matches any string formed by concatenating
697 two substrings that respectively match the concatenated
698 expressions.
699 .SS Alternation
700 Two regular expressions may be joined by the infix operator
701 .BR | ;
702 the resulting regular expression matches any string matching
703 either alternate expression.
704 .SS Precedence
705 Repetition takes precedence over concatenation, which in turn
706 takes precedence over alternation.
707 A whole expression may be enclosed in parentheses
708 to override these precedence rules and form a subexpression.
709 .SS "Back References and Subexpressions"
710 The back-reference
711 .BI \e n\c
712 \&, where
713 .I n
714 is a single digit, matches the substring
715 previously matched by the
716 .IR n th
717 parenthesized subexpression of the regular expression.
718 .SS "Basic vs Extended Regular Expressions"
719 In basic regular expressions the meta-characters
720 .BR ? ,
721 .BR + ,
722 .BR { ,
723 .BR | ,
724 .BR ( ,
725 and
726 .BR )
727 lose their special meaning; instead use the backslashed
728 versions
729 .BR \e? ,
730 .BR \e+ ,
731 .BR \e{ ,
732 .BR \e| ,
733 .BR \e( ,
734 and
735 .BR \e) .
736 .
737 .SH "ENVIRONMENT VARIABLES"
738 The behavior of
739 .B grep
740 is affected by the following environment variables.
741 .PP
742 The locale for category
743 .BI LC_ foo
744 is specified by examining the three environment variables
745 .BR LC_ALL ,
746 .BR LC_\fIfoo\fP ,
747 .BR LANG ,
748 in that order.
749 The first of these variables that is set specifies the locale.
750 For example, if
751 .B LC_ALL
752 is not set, but
753 .B LC_MESSAGES
754 is set to
755 .BR pt_BR ,
756 then the Brazilian Portuguese locale is used for the
757 .B LC_MESSAGES
758 category.
759 The C locale is used if none of these environment variables are set,
760 if the locale catalog is not installed, or if
761 .B grep
762 was not compiled with national language support (\s-1NLS\s0).
763 .TP
764 .B GREP_OPTIONS
765 This variable specifies default options
766 to be placed in front of any explicit options.
767 As this causes problems when writing portable scripts,
768 this feature will be removed in a future release of
769 .BR grep ,
770 and
771 .B grep
772 warns if it is used.
773 Please use an alias or script instead.
774 .TP
775 .B GREP_COLOR
776 This variable specifies the color used to highlight matched (non-empty) text.
777 It is deprecated in favor of
778 .BR GREP_COLORS ,
779 but still supported.
780 The
781 .BR mt ,
782 .BR ms ,
783 and
784 .B mc
785 capabilities of
786 .B GREP_COLORS
787 have priority over it.
788 It can only specify the color used to highlight
789 the matching non-empty text in any matching line
790 (a selected line when the
791 .B -v
792 command-line option is omitted,
793 or a context line when
794 .B -v
795 is specified).
796 The default is
797 .BR 01;31 ,
798 which means a bold red foreground text on the terminal's default background.
799 .TP
800 .B GREP_COLORS
801 Specifies the colors and other attributes
802 used to highlight various parts of the output.
803 Its value is a colon-separated list of capabilities
804 that defaults to
805 .B ms=01;31:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36
806 with the
807 .B rv
808 and
809 .B ne
810 boolean capabilities omitted (i.e., false).
811 Supported capabilities are as follows.
812 .RS
813 .TP
814 .B sl=
815 SGR substring for whole selected lines
816 (i.e.,
817 matching lines when the
818 .B \-v
819 command-line option is omitted,
820 or non-matching lines when
821 .B \-v
822 is specified).
823 If however the boolean
824 .B rv
825 capability
826 and the
827 .B \-v
828 command-line option are both specified,
829 it applies to context matching lines instead.
830 The default is empty (i.e., the terminal's default color pair).
831 .TP
832 .B cx=
833 SGR substring for whole context lines
834 (i.e.,
835 non-matching lines when the
836 .B \-v
837 command-line option is omitted,
838 or matching lines when
839 .B \-v
840 is specified).
841 If however the boolean
842 .B rv
843 capability
844 and the
845 .B \-v
846 command-line option are both specified,
847 it applies to selected non-matching lines instead.
848 The default is empty (i.e., the terminal's default color pair).
849 .TP
850 .B rv
851 Boolean value that reverses (swaps) the meanings of
852 the
853 .B sl=
854 and
855 .B cx=
856 capabilities
857 when the
858 .B \-v
859 command-line option is specified.
860 The default is false (i.e., the capability is omitted).
861 .TP
862 .B mt=01;31
863 SGR substring for matching non-empty text in any matching line
864 (i.e.,
865 a selected line when the
866 .B \-v
867 command-line option is omitted,
868 or a context line when
869 .B \-v
870 is specified).
871 Setting this is equivalent to setting both
872 .B ms=
873 and
874 .B mc=
875 at once to the same value.
876 The default is a bold red text foreground over the current line background.
877 .TP
878 .B ms=01;31
879 SGR substring for matching non-empty text in a selected line.
880 (This is only used when the
881 .B \-v
882 command-line option is omitted.)
883 The effect of the
884 .B sl=
885 (or
886 .B cx=
887 if
888 .BR rv )
889 capability remains active when this kicks in.
890 The default is a bold red text foreground over the current line background.
891 .TP
892 .B mc=01;31
893 SGR substring for matching non-empty text in a context line.
894 (This is only used when the
895 .B \-v
896 command-line option is specified.)
897 The effect of the
898 .B cx=
899 (or
900 .B sl=
901 if
902 .BR rv )
903 capability remains active when this kicks in.
904 The default is a bold red text foreground over the current line background.
905 .TP
906 .B fn=35
907 SGR substring for file names prefixing any content line.
908 The default is a magenta text foreground over the terminal's default background.
909 .TP
910 .B ln=32
911 SGR substring for line numbers prefixing any content line.
912 The default is a green text foreground over the terminal's default background.
913 .TP
914 .B bn=32
915 SGR substring for byte offsets prefixing any content line.
916 The default is a green text foreground over the terminal's default background.
917 .TP
918 .B se=36
919 SGR substring for separators that are inserted
920 between selected line fields
921 .RB ( : ),
922 between context line fields,
923 .RB ( \- ),
924 and between groups of adjacent lines when nonzero context is specified
925 .RB ( \-\^\- ).
926 The default is a cyan text foreground over the terminal's default background.
927 .TP
928 .B ne
929 Boolean value that prevents clearing to the end of line
930 using Erase in Line (EL) to Right
931 .RB ( \\\\\\33[K )
932 each time a colorized item ends.
933 This is needed on terminals on which EL is not supported.
934 It is otherwise useful on terminals
935 for which the
936 .B back_color_erase
937 .RB ( bce )
938 boolean terminfo capability does not apply,
939 when the chosen highlight colors do not affect the background,
940 or when EL is too slow or causes too much flicker.
941 The default is false (i.e., the capability is omitted).
942 .PP
943 Note that boolean capabilities have no
944 .BR = ...
945 part.
946 They are omitted (i.e., false) by default and become true when specified.
947 .PP
948 See the Select Graphic Rendition (SGR) section
949 in the documentation of the text terminal that is used
950 for permitted values and their meaning as character attributes.
951 These substring values are integers in decimal representation
952 and can be concatenated with semicolons.
953 .B grep
954 takes care of assembling the result
955 into a complete SGR sequence
956 .RB ( \\\\\\33[ ... m ).
957 Common values to concatenate include
958 .B 1
959 for bold,
960 .B 4
961 for underline,
962 .B 5
963 for blink,
964 .B 7
965 for inverse,
966 .B 39
967 for default foreground color,
968 .B 30
969 to
970 .B 37
971 for foreground colors,
972 .B 90
973 to
974 .B 97
975 for 16-color mode foreground colors,
976 .B 38;5;0
977 to
978 .B 38;5;255
979 for 88-color and 256-color modes foreground colors,
980 .B 49
981 for default background color,
982 .B 40
983 to
984 .B 47
985 for background colors,
986 .B 100
987 to
988 .B 107
989 for 16-color mode background colors, and
990 .B 48;5;0
991 to
992 .B 48;5;255
993 for 88-color and 256-color modes background colors.
994 .RE
995 .TP
996 \fBLC_ALL\fP, \fBLC_COLLATE\fP, \fBLANG\fP
997 These variables specify the locale for the
998 .B LC_COLLATE
999 category,
1000 which determines the collating sequence
1001 used to interpret range expressions like
1002 .BR [a\-z] .
1003 .TP
1004 \fBLC_ALL\fP, \fBLC_CTYPE\fP, \fBLANG\fP
1005 These variables specify the locale for the
1006 .B LC_CTYPE
1007 category,
1008 which determines the type of characters,
1009 e.g., which characters are whitespace.
1010 .TP
1011 \fBLC_ALL\fP, \fBLC_MESSAGES\fP, \fBLANG\fP
1012 These variables specify the locale for the
1013 .B LC_MESSAGES
1014 category,
1015 which determines the language that
1016 .B grep
1017 uses for messages.
1018 The default C locale uses American English messages.
1019 .TP
1020 .B POSIXLY_CORRECT
1021 If set,
1022 .B grep
1023 behaves as \s-1POSIX\s0 requires; otherwise,
1024 .B grep
1025 behaves more like other \s-1GNU\s0 programs.
1026 \s-1POSIX\s0 requires that options that follow file names must be
1027 treated as file names; by default, such options are permuted to the
1028 front of the operand list and are treated as options.
1029 Also, \s-1POSIX\s0 requires that unrecognized options be diagnosed as
1030 \*(lqillegal\*(rq, but since they are not really against the law the default
1031 is to diagnose them as \*(lqinvalid\*(rq.
1032 .B POSIXLY_CORRECT
1033 also disables \fB_\fP\fIN\fP\fB_GNU_nonoption_argv_flags_\fP,
1034 described below.
1035 .TP
1036 \fB_\fP\fIN\fP\fB_GNU_nonoption_argv_flags_\fP
1037 (Here
1038 .I N
1039 is
1040 .BR grep 's
1041 numeric process ID.)  If the
1042 .IR i th
1043 character of this environment variable's value is
1044 .BR 1 ,
1045 do not consider the
1046 .IR i th
1047 operand of
1048 .B grep
1049 to be an option, even if it appears to be one.
1050 A shell can put this variable in the environment for each command it runs,
1051 specifying which operands are the results of file name wildcard
1052 expansion and therefore should not be treated as options.
1053 This behavior is available only with the \s-1GNU\s0 C library, and only
1054 when
1055 .B POSIXLY_CORRECT
1056 is not set.
1057 .
1058 .SH "EXIT STATUS"
1059 Normally the exit status is 0 if a line is selected, 1 if no lines
1060 were selected, and 2 if an error occurred.  However, if the
1061 .B \-q
1062 or
1063 .B \-\^\-quiet
1064 or
1065 .B \-\^\-silent
1066 is used and a line is selected, the exit status is 0 even if an error
1067 occurred.
1068 .
1069 .SH COPYRIGHT
1070 Copyright 1998-2000, 2002, 2005-2015 Free Software Foundation, Inc.
1071 .PP
1072 This is free software;
1073 see the source for copying conditions.
1074 There is NO warranty;
1075 not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1076 .
1077 .SH BUGS
1078 .SS "Reporting Bugs"
1079 Email bug reports to
1080 .MTO bug-grep@gnu.org "the bug-reporting address" .
1081 An
1082 .URL http://lists.gnu.org/mailman/listinfo/bug-grep "email archive"
1083 and a
1084 .URL http://debbugs.gnu.org/cgi/pkgreport.cgi?package=grep "bug tracker"
1085 are available.
1086 .SS "Known Bugs"
1087 Large repetition counts in the
1088 .BI { n , m }
1089 construct may cause
1090 .B grep
1091 to use lots of memory.
1092 In addition,
1093 certain other obscure regular expressions require exponential time
1094 and space, and may cause
1095 .B grep
1096 to run out of memory.
1097 .PP
1098 Back-references are very slow, and may require exponential time.
1099 .
1100 .SH "SEE ALSO"
1101 .SS "Regular Manual Pages"
1102 awk(1), cmp(1), diff(1), find(1), gzip(1),
1103 perl(1), sed(1), sort(1), xargs(1), zgrep(1),
1104 read(2),
1105 pcre(3), pcresyntax(3), pcrepattern(3),
1106 terminfo(5),
1107 glob(7), regex(7).
1108 .SS "\s-1POSIX\s0 Programmer's Manual Page"
1109 grep(1p).
1110 .SS "Full Documentation"
1111 A
1112 .URL http://www.gnu.org/software/grep/manual/ "complete manual"
1113 is available.
1114 If the
1115 .B info
1116 and
1117 .B grep
1118 programs are properly installed at your site, the command
1119 .IP
1120 .B info grep
1121 .PP
1122 should give you access to the complete manual.
1123 .
1124 .SH NOTES
1125 This man page is maintained only fitfully;
1126 the full documentation is often more up-to-date.
1127 .\" Work around problems with some troff -man implementations.
1128 .br