VirtualBox

source: kBuild/vendor/grep/2.12/doc/grep.in.1

Last change on this file was 2595, checked in by bird, 12 years ago

gnu grep version 2.12 (grep-2.12.tar.xz, md5sum=8d2f0346d08b13c18afb81f0e8aa1e2f)

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette