1 \input texinfo @c -*-texinfo-*-
5 @settitle GNU Grep @value{VERSION}
16 @documentencoding UTF-8
19 This manual is for @command{grep}, a pattern matching engine.
21 Copyright @copyright{} 1999--2002, 2005, 2008--2014 Free Software Foundation,
25 Permission is granted to copy, distribute and/or modify this document
26 under the terms of the GNU Free Documentation License, Version 1.3 or
27 any later version published by the Free Software Foundation; with no
28 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
29 Texts. A copy of the license is included in the section entitled
30 ``GNU Free Documentation License''.
34 @dircategory Text creation and manipulation
36 * grep: (grep). Print lines matching a pattern.
40 @title GNU Grep: Print lines matching a pattern
41 @subtitle version @value{VERSION}, @value{UPDATED}
42 @author Alain Magloire et al.
44 @vskip 0pt plus 1filll
55 @command{grep} prints lines that contain a match for a pattern.
57 This manual is for version @value{VERSION} of GNU Grep.
63 * Introduction:: Introduction.
64 * Invoking:: Command-line options, environment, exit status.
65 * Regular Expressions:: Regular Expressions.
67 * Reporting Bugs:: Reporting Bugs.
68 * Copying:: License terms for this manual.
69 * Index:: Combined index.
76 @cindex searching for a pattern
78 @command{grep} searches input files
79 for lines containing a match to a given pattern list.
80 When it finds a match in a line,
81 it copies the line to standard output (by default),
82 or produces whatever other sort of output you have requested with options.
84 Though @command{grep} expects to do the matching on text,
85 it has no limits on input line length other than available memory,
86 and it can match arbitrary characters within a line.
87 If the final byte of an input file is not a newline,
88 @command{grep} silently supplies one.
89 Since newline is also a separator for the list of patterns,
90 there is no way to match newline characters in a text.
94 @chapter Invoking @command{grep}
96 The general synopsis of the @command{grep} command line is
99 grep @var{options} @var{pattern} @var{input_file_names}
103 There can be zero or more @var{options}.
104 @var{pattern} will only be seen as such
105 (and not as an @var{input_file_name})
106 if it wasn't already specified within @var{options}
107 (by using the @samp{-e@ @var{pattern}}
108 or @samp{-f@ @var{file}} options).
109 There can be zero or more @var{input_file_names}.
112 * Command-line Options:: Short and long names, grouped by category.
113 * Environment Variables:: POSIX, GNU generic, and GNU grep specific.
114 * Exit Status:: Exit status returned by @command{grep}.
115 * grep Programs:: @command{grep} programs.
118 @node Command-line Options
119 @section Command-line Options
121 @command{grep} comes with a rich set of options:
122 some from POSIX and some being GNU extensions.
123 Long option names are always a GNU extension,
124 even for options that are from POSIX specifications.
125 Options that are specified by POSIX,
126 under their short names,
127 are explicitly marked as such
128 to facilitate POSIX-portable programming.
129 A few option names are provided
130 for compatibility with older or more exotic implementations.
133 * Generic Program Information::
135 * General Output Control::
136 * Output Line Prefix Control::
137 * Context Line Control::
138 * File and Directory Selection::
142 Several additional options control
143 which variant of the @command{grep} matching engine is used.
144 @xref{grep Programs}.
146 @node Generic Program Information
147 @subsection Generic Program Information
153 @cindex usage summary, printing
154 Print a usage message briefly summarizing the command-line options
155 and the bug-reporting address, then exit.
161 @cindex version, printing
162 Print the version number of @command{grep} to the standard output stream.
163 This version number should be included in all bug reports.
167 @node Matching Control
168 @subsection Matching Control
172 @item -e @var{pattern}
173 @itemx --regexp=@var{pattern}
175 @opindex --regexp=@var{pattern}
177 Use @var{pattern} as the pattern.
178 This can be used to specify multiple search patterns,
179 or to protect a pattern beginning with a @samp{-}.
180 (@option{-e} is specified by POSIX.)
183 @itemx --file=@var{file}
186 @cindex pattern from file
187 Obtain patterns from @var{file}, one per line.
188 The empty file contains zero patterns, and therefore matches nothing.
189 (@option{-f} is specified by POSIX.)
196 @opindex --ignore-case
197 @cindex case insensitive search
198 Ignore case distinctions, so that characters that differ only in case
199 match each other. Although this is straightforward when letters
200 differ in case only via lowercase-uppercase pairs, the behavior is
201 unspecified in other situations. For example, uppercase ``S'' has an
202 unusual lowercase counterpart ``ſ'' (Unicode character U+017F, LATIN
203 SMALL LETTER LONG S) in many locales, and it is unspecified whether
204 this unusual character matches ``S'' or ``s'' even though uppercasing
205 it yields ``S''. Another example: the lowercase German letter ``ß''
206 (U+00DF, LATIN SMALL LETTER SHARP S) is normally capitalized as the
207 two-character string ``SS'' but it does not match ``SS'', and it might
208 not match the uppercase letter ``ẞ'' (U+1E9E, LATIN CAPITAL LETTER
209 SHARP S) even though lowercasing the latter yields the former.
211 @option{-y} is an obsolete synonym that is provided for compatibility.
212 (@option{-i} is specified by POSIX.)
215 @itemx --invert-match
217 @opindex --invert-match
218 @cindex invert matching
219 @cindex print non-matching lines
220 Invert the sense of matching, to select non-matching lines.
221 (@option{-v} is specified by POSIX.)
226 @opindex --word-regexp
227 @cindex matching whole words
228 Select only those lines containing matches that form whole words.
229 The test is that the matching substring must either
230 be at the beginning of the line,
231 or preceded by a non-word constituent character.
233 it must be either at the end of the line
234 or followed by a non-word constituent character.
235 Word-constituent characters are letters, digits, and the underscore.
240 @opindex --line-regexp
241 @cindex match the whole line
242 Select only those matches that exactly match the whole line.
243 (@option{-x} is specified by POSIX.)
247 @node General Output Control
248 @subsection General Output Control
256 @cindex counting lines
257 Suppress normal output;
258 instead print a count of matching lines for each input file.
259 With the @option{-v} (@option{--invert-match}) option,
260 count non-matching lines.
261 (@option{-c} is specified by POSIX.)
263 @item --color[=@var{WHEN}]
264 @itemx --colour[=@var{WHEN}]
267 @cindex highlight, color, colour
268 Surround the matched (non-empty) strings, matching lines, context lines,
269 file names, line numbers, byte offsets, and separators (for fields and
270 groups of context lines) with escape sequences to display them in color
272 The colors are defined by the environment variable @env{GREP_COLORS}
273 and default to @samp{ms=01;31:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36}
274 for bold red matched text, magenta file names, green line numbers,
275 green byte offsets, cyan separators, and default terminal colors otherwise.
276 The deprecated environment variable @env{GREP_COLOR} is still supported,
277 but its setting does not have priority;
278 it defaults to @samp{01;31} (bold red)
279 which only covers the color for matched text.
280 @var{WHEN} is @samp{never}, @samp{always}, or @samp{auto}.
283 @itemx --files-without-match
285 @opindex --files-without-match
286 @cindex files which don't match
287 Suppress normal output;
288 instead print the name of each input file from which
289 no output would normally have been printed.
290 The scanning of each file stops on the first match.
293 @itemx --files-with-matches
295 @opindex --files-with-matches
296 @cindex names of matching files
297 Suppress normal output;
298 instead print the name of each input file from which
299 output would normally have been printed.
300 The scanning of each file stops on the first match.
301 (@option{-l} is specified by POSIX.)
304 @itemx --max-count=@var{num}
308 Stop reading a file after @var{num} matching lines.
309 If the input is standard input from a regular file,
310 and @var{num} matching lines are output,
311 @command{grep} ensures that the standard input is positioned
312 just after the last matching line before exiting,
313 regardless of the presence of trailing context lines.
314 This enables a calling process to resume a search.
315 For example, the following shell script makes use of it:
318 while grep -m 1 PATTERN
324 But the following probably will not work because a pipe is not a regular
328 # This probably will not work.
330 while grep -m 1 PATTERN
336 When @command{grep} stops after @var{num} matching lines,
337 it outputs any trailing context lines.
338 Since context does not include matching lines,
339 @command{grep} will stop when it encounters another matching line.
340 When the @option{-c} or @option{--count} option is also used,
341 @command{grep} does not output a count greater than @var{num}.
342 When the @option{-v} or @option{--invert-match} option is also used,
343 @command{grep} stops after outputting @var{num} non-matching lines.
346 @itemx --only-matching
348 @opindex --only-matching
349 @cindex only matching
350 Print only the matched (non-empty) parts of matching lines,
351 with each such part on a separate output line.
359 @cindex quiet, silent
360 Quiet; do not write anything to standard output.
361 Exit immediately with zero status if any match is found,
362 even if an error was detected.
363 Also see the @option{-s} or @option{--no-messages} option.
364 (@option{-q} is specified by POSIX.)
369 @opindex --no-messages
370 @cindex suppress error messages
371 Suppress error messages about nonexistent or unreadable files.
373 unlike GNU @command{grep},
374 7th Edition Unix @command{grep} did not conform to POSIX,
375 because it lacked @option{-q}
376 and its @option{-s} option behaved like
377 GNU @command{grep}'s @option{-q} option.@footnote{Of course, 7th Edition
378 Unix predated POSIX by several years!}
379 USG-style @command{grep} also lacked @option{-q}
380 but its @option{-s} option behaved like GNU @command{grep}'s.
381 Portable shell scripts should avoid both
382 @option{-q} and @option{-s} and should redirect
383 standard and error output to @file{/dev/null} instead.
384 (@option{-s} is specified by POSIX.)
388 @node Output Line Prefix Control
389 @subsection Output Line Prefix Control
391 When several prefix fields are to be output,
392 the order is always file name, line number, and byte offset,
393 regardless of the order in which these options were specified.
400 @opindex --byte-offset
402 Print the 0-based byte offset within the input file
403 before each line of output.
404 If @option{-o} (@option{--only-matching}) is specified,
405 print the offset of the matching part itself.
406 When @command{grep} runs on MS-DOS or MS-Windows,
407 the printed byte offsets depend on whether
408 the @option{-u} (@option{--unix-byte-offsets}) option is used;
412 @itemx --with-filename
414 @opindex --with-filename
415 @cindex with filename prefix
416 Print the file name for each match.
417 This is the default when there is more than one file to search.
422 @opindex --no-filename
423 @cindex no filename prefix
424 Suppress the prefixing of file names on output.
425 This is the default when there is only one file
426 (or only standard input) to search.
428 @item --label=@var{LABEL}
430 @cindex changing name of standard input
431 Display input actually coming from standard input
432 as input coming from file @var{LABEL}. This is
433 especially useful when implementing tools like
434 @command{zgrep}; e.g.:
437 gzip -cd foo.gz | grep --label=foo -H something
443 @opindex --line-number
444 @cindex line numbering
445 Prefix each line of output with the 1-based line number within its input file.
446 (@option{-n} is specified by POSIX.)
451 @opindex --initial-tab
452 @cindex tab-aligned content lines
453 Make sure that the first character of actual line content lies on a tab stop,
454 so that the alignment of tabs looks normal.
455 This is useful with options that prefix their output to the actual content:
456 @option{-H}, @option{-n}, and @option{-b}.
457 In order to improve the probability that lines
458 from a single file will all start at the same column,
459 this also causes the line number and byte offset (if present)
460 to be printed in a minimum-size field width.
463 @itemx --unix-byte-offsets
465 @opindex --unix-byte-offsets
466 @cindex MS-DOS/MS-Windows byte offsets
467 @cindex byte offsets, on MS-DOS/MS-Windows
468 Report Unix-style byte offsets.
469 This option causes @command{grep} to report byte offsets
470 as if the file were a Unix-style text file,
471 i.e., the byte offsets ignore the @code{CR} characters that were stripped.
472 This will produce results identical
473 to running @command{grep} on a Unix machine.
474 This option has no effect unless the @option{-b} option is also used;
475 it has no effect on platforms other than MS-DOS and MS-Windows.
481 @cindex zero-terminated file names
482 Output a zero byte (the ASCII @code{NUL} character)
483 instead of the character that normally follows a file name.
485 @samp{grep -lZ} outputs a zero byte after each file name
486 instead of the usual newline.
487 This option makes the output unambiguous,
488 even in the presence of file names containing unusual characters like newlines.
489 This option can be used with commands like
490 @samp{find -print0}, @samp{perl -0}, @samp{sort -z}, and @samp{xargs -0}
491 to process arbitrary file names,
492 even those that contain newline characters.
496 @node Context Line Control
497 @subsection Context Line Control
499 Regardless of how these options are set,
500 @command{grep} will never print any given line more than once.
501 If the @option{-o} (@option{--only-matching}) option is specified,
502 these options have no effect and a warning is given upon their use.
507 @itemx --after-context=@var{num}
509 @opindex --after-context
510 @cindex after context
511 @cindex context lines, after match
512 Print @var{num} lines of trailing context after matching lines.
515 @itemx --before-context=@var{num}
517 @opindex --before-context
518 @cindex before context
519 @cindex context lines, before match
520 Print @var{num} lines of leading context before matching lines.
524 @itemx --context=@var{num}
529 Print @var{num} lines of leading and trailing output context.
531 @item --group-separator=@var{string}
532 @opindex --group-separator
533 @cindex group separator
534 When @option{-A}, @option{-B} or @option{-C} are in use,
535 print @var{string} instead of @option{--} between groups of lines.
537 @item --no-group-separator
538 @opindex --group-separator
539 @cindex group separator
540 When @option{-A}, @option{-B} or @option{-C} are in use,
541 do not print a separator between groups of lines.
545 Here are some points about how @command{grep} chooses
546 the separator to print between prefix fields and line content:
550 Matching lines normally use @samp{:} as a separator
551 between prefix fields and actual line content.
554 Context (i.e., non-matching) lines use @samp{-} instead.
557 When context is not specified,
558 matching lines are simply output one right after another.
561 When context is specified,
562 lines that are adjacent in the input form a group
563 and are output one right after another, while
564 by default a separator appears between non-adjacent groups.
567 The default separator
568 is a @samp{--} line; its presence and appearance
569 can be changed with the options above.
572 Each group may contain
573 several matching lines when they are close enough to each other
574 that two adjacent groups connect and can merge into a single
578 @node File and Directory Selection
579 @subsection File and Directory Selection
587 @cindex suppress binary data
589 Process a binary file as if it were text;
590 this is equivalent to the @samp{--binary-files=text} option.
592 @item --binary-files=@var{type}
593 @opindex --binary-files
595 If a file's allocation metadata or its first few bytes
596 indicate that the file contains binary data,
597 assume that the file is of type @var{type}.
598 By default, @var{type} is @samp{binary},
599 and @command{grep} normally outputs either
600 a one-line message saying that a binary file matches,
601 or no message if there is no match.
603 If @var{type} is @samp{without-match},
604 @command{grep} assumes that a binary file does not match;
605 this is equivalent to the @option{-I} option.
607 If @var{type} is @samp{text},
608 @command{grep} processes a binary file as if it were text;
609 this is equivalent to the @option{-a} option.
611 @emph{Warning:} @samp{--binary-files=text} might output binary garbage,
612 which can have nasty side effects
613 if the output is a terminal and
614 if the terminal driver interprets some of it as commands.
616 @item -D @var{action}
617 @itemx --devices=@var{action}
620 @cindex device search
621 If an input file is a device, FIFO, or socket, use @var{action} to process it.
622 If @var{action} is @samp{read},
623 all devices are read just as if they were ordinary files.
624 If @var{action} is @samp{skip},
625 devices, FIFOs, and sockets are silently skipped.
626 By default, devices are read if they are on the command line or if the
627 @option{-R} (@option{--dereference-recursive}) option is used, and are
628 skipped if they are encountered recursively and the @option{-r}
629 (@option{--recursive}) option is used.
630 This option has no effect on a file that is read via standard input.
632 @item -d @var{action}
633 @itemx --directories=@var{action}
635 @opindex --directories
636 @cindex directory search
637 @cindex symbolic links
638 If an input file is a directory, use @var{action} to process it.
639 By default, @var{action} is @samp{read},
640 which means that directories are read just as if they were ordinary files
641 (some operating systems and file systems disallow this,
642 and will cause @command{grep}
643 to print error messages for every directory or silently skip them).
644 If @var{action} is @samp{skip}, directories are silently skipped.
645 If @var{action} is @samp{recurse},
646 @command{grep} reads all files under each directory, recursively,
647 following command-line symbolic links and skipping other symlinks;
648 this is equivalent to the @option{-r} option.
650 @item --exclude=@var{glob}
652 @cindex exclude files
653 @cindex searching directory trees
654 Skip files whose base name matches @var{glob}
655 (using wildcard matching).
656 A file-name glob can use
657 @samp{*}, @samp{?}, and @samp{[}...@samp{]} as wildcards,
658 and @code{\} to quote a wildcard or backslash character literally.
660 @item --exclude-from=@var{file}
661 @opindex --exclude-from
662 @cindex exclude files
663 @cindex searching directory trees
664 Skip files whose base name matches any of the file-name globs
665 read from @var{file} (using wildcard matching as described
666 under @option{--exclude}).
668 @item --exclude-dir=@var{dir}
669 @opindex --exclude-dir
670 @cindex exclude directories
671 Skip any directory whose name matches the pattern @var{dir}, ignoring
672 any redundant trailing slashes in @var{dir}.
675 Process a binary file as if it did not contain matching data;
676 this is equivalent to the @samp{--binary-files=without-match} option.
678 @item --include=@var{glob}
680 @cindex include files
681 @cindex searching directory trees
682 Search only files whose base name matches @var{glob}
683 (using wildcard matching as described under @option{--exclude}).
689 @cindex recursive search
690 @cindex searching directory trees
691 @cindex symbolic links
692 For each directory operand,
693 read and process all files in that directory, recursively.
694 Follow symbolic links on the command line, but skip symlinks
695 that are encountered recursively.
696 This is the same as the @samp{--directories=recurse} option.
699 @itemx --dereference-recursive
701 @opindex --dereference-recursive
702 @cindex recursive search
703 @cindex searching directory trees
704 @cindex symbolic links
705 For each directory operand, read and process all files in that
706 directory, recursively, following all symbolic links.
711 @subsection Other Options
715 @item --line-buffered
716 @opindex --line-buffered
717 @cindex line buffering
718 Use line buffering on output.
719 This can cause a performance penalty.
725 @cindex MS-DOS/MS-Windows binary files
726 @cindex binary files, MS-DOS/MS-Windows
727 Treat the file(s) as binary.
728 By default, under MS-DOS and MS-Windows,
729 @command{grep} guesses whether a file is text or binary
730 as described for the @option{--binary-files} option.
731 If @command{grep} decides the file is a text file,
732 it strips the @code{CR} characters from the original file contents
733 (to make regular expressions with @code{^} and @code{$} work correctly).
734 Specifying @option{-U} overrules this guesswork,
735 causing all files to be read and passed to the matching mechanism verbatim;
736 if the file is a text file with @code{CR/LF} pairs at the end of each line,
737 this will cause some regular expressions to fail.
738 This option has no effect
739 on platforms other than MS-DOS and MS-Windows.
745 @cindex zero-terminated lines
746 Treat the input as a set of lines, each terminated by a zero byte (the
747 ASCII @code{NUL} character) instead of a newline.
748 Like the @option{-Z} or @option{--null} option,
749 this option can be used with commands like
750 @samp{sort -z} to process arbitrary file names.
754 @node Environment Variables
755 @section Environment Variables
757 The behavior of @command{grep} is affected
758 by the following environment variables.
760 The locale for category @w{@code{LC_@var{foo}}}
761 is specified by examining the three environment variables
762 @env{LC_ALL}, @w{@env{LC_@var{foo}}}, and @env{LANG},
764 The first of these variables that is set specifies the locale.
765 For example, if @env{LC_ALL} is not set,
766 but @env{LC_MESSAGES} is set to @samp{pt_BR},
767 then the Brazilian Portuguese locale is used
768 for the @code{LC_MESSAGES} category.
769 The @samp{C} locale is used if none of these environment variables are set,
770 if the locale catalog is not installed,
771 or if @command{grep} was not compiled
772 with national language support (NLS).
774 Many of the environment variables in the following list let you
775 control highlighting using
776 Select Graphic Rendition (SGR)
777 commands interpreted by the terminal or terminal emulator.
780 in the documentation of your text terminal
781 for permitted values and their meanings as character attributes.)
782 These substring values are integers in decimal representation
783 and can be concatenated with semicolons.
784 @command{grep} takes care of assembling the result
785 into a complete SGR sequence (@samp{\33[}...@samp{m}).
786 Common values to concatenate include
788 @samp{4} for underline,
790 @samp{7} for inverse,
791 @samp{39} for default foreground color,
792 @samp{30} to @samp{37} for foreground colors,
793 @samp{90} to @samp{97} for 16-color mode foreground colors,
794 @samp{38;5;0} to @samp{38;5;255}
795 for 88-color and 256-color modes foreground colors,
796 @samp{49} for default background color,
797 @samp{40} to @samp{47} for background colors,
798 @samp{100} to @samp{107} for 16-color mode background colors,
799 and @samp{48;5;0} to @samp{48;5;255}
800 for 88-color and 256-color modes background colors.
802 The two-letter names used in the @env{GREP_COLORS} environment variable
803 (and some of the others) refer to terminal ``capabilities,'' the ability
804 of a terminal to highlight text, or change its color, and so on.
805 These capabilities are stored in an online database and accessed by
806 the @code{terminfo} library.
808 @cindex environment variables
813 @vindex GREP_OPTIONS @r{environment variable}
814 @cindex default options environment variable
815 This variable specifies default options to be placed in front of any
817 For example, if @code{GREP_OPTIONS} is
818 @samp{--binary-files=without-match --directories=skip}, @command{grep}
819 behaves as if the two options @samp{--binary-files=without-match} and
820 @samp{--directories=skip} had been specified before
821 any explicit options.
822 Option specifications are separated by
824 A backslash escapes the next character, so it can be used to
825 specify an option containing whitespace or a backslash.
827 The @code{GREP_OPTIONS} value does not affect whether @command{grep}
828 without file operands searches standard input or the working
829 directory; that is affected only by command-line options. For
830 example, the command @samp{grep PAT} searches standard input and the
831 command @samp{grep -r PAT} searches the working directory, regardless
832 of whether @code{GREP_OPTIONS} contains @option{-r}.
835 @vindex GREP_COLOR @r{environment variable}
836 @cindex highlight markers
837 This variable specifies the color used to highlight matched (non-empty) text.
838 It is deprecated in favor of @env{GREP_COLORS}, but still supported.
839 The @samp{mt}, @samp{ms}, and @samp{mc} capabilities of @env{GREP_COLORS}
840 have priority over it.
841 It can only specify the color used to highlight
842 the matching non-empty text in any matching line
843 (a selected line when the @option{-v} command-line option is omitted,
844 or a context line when @option{-v} is specified).
845 The default is @samp{01;31},
846 which means a bold red foreground text on the terminal's default background.
849 @vindex GREP_COLORS @r{environment variable}
850 @cindex highlight markers
851 This variable specifies the colors and other attributes
852 used to highlight various parts of the output.
853 Its value is a colon-separated list of @code{terminfo} capabilities
854 that defaults to @samp{ms=01;31:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36}
855 with the @samp{rv} and @samp{ne} boolean capabilities omitted (i.e., false).
856 Supported capabilities are as follows.
860 @vindex sl GREP_COLORS @r{capability}
861 SGR substring for whole selected lines
863 matching lines when the @option{-v} command-line option is omitted,
864 or non-matching lines when @option{-v} is specified).
865 If however the boolean @samp{rv} capability
866 and the @option{-v} command-line option are both specified,
867 it applies to context matching lines instead.
868 The default is empty (i.e., the terminal's default color pair).
871 @vindex cx GREP_COLORS @r{capability}
872 SGR substring for whole context lines
874 non-matching lines when the @option{-v} command-line option is omitted,
875 or matching lines when @option{-v} is specified).
876 If however the boolean @samp{rv} capability
877 and the @option{-v} command-line option are both specified,
878 it applies to selected non-matching lines instead.
879 The default is empty (i.e., the terminal's default color pair).
882 @vindex rv GREP_COLORS @r{capability}
883 Boolean value that reverses (swaps) the meanings of
884 the @samp{sl=} and @samp{cx=} capabilities
885 when the @option{-v} command-line option is specified.
886 The default is false (i.e., the capability is omitted).
889 @vindex mt GREP_COLORS @r{capability}
890 SGR substring for matching non-empty text in any matching line
892 a selected line when the @option{-v} command-line option is omitted,
893 or a context line when @option{-v} is specified).
894 Setting this is equivalent to setting both @samp{ms=} and @samp{mc=}
895 at once to the same value.
896 The default is a bold red text foreground over the current line background.
899 @vindex ms GREP_COLORS @r{capability}
900 SGR substring for matching non-empty text in a selected line.
901 (This is used only when the @option{-v} command-line option is omitted.)
902 The effect of the @samp{sl=} (or @samp{cx=} if @samp{rv}) capability
903 remains active when this takes effect.
904 The default is a bold red text foreground over the current line background.
907 @vindex mc GREP_COLORS @r{capability}
908 SGR substring for matching non-empty text in a context line.
909 (This is used only when the @option{-v} command-line option is specified.)
910 The effect of the @samp{cx=} (or @samp{sl=} if @samp{rv}) capability
911 remains active when this takes effect.
912 The default is a bold red text foreground over the current line background.
915 @vindex fn GREP_COLORS @r{capability}
916 SGR substring for file names prefixing any content line.
917 The default is a magenta text foreground over the terminal's default background.
920 @vindex ln GREP_COLORS @r{capability}
921 SGR substring for line numbers prefixing any content line.
922 The default is a green text foreground over the terminal's default background.
925 @vindex bn GREP_COLORS @r{capability}
926 SGR substring for byte offsets prefixing any content line.
927 The default is a green text foreground over the terminal's default background.
930 @vindex fn GREP_COLORS @r{capability}
931 SGR substring for separators that are inserted
932 between selected line fields (@samp{:}),
933 between context line fields (@samp{-}),
934 and between groups of adjacent lines
935 when nonzero context is specified (@samp{--}).
936 The default is a cyan text foreground over the terminal's default background.
939 @vindex ne GREP_COLORS @r{capability}
940 Boolean value that prevents clearing to the end of line
941 using Erase in Line (EL) to Right (@samp{\33[K})
942 each time a colorized item ends.
943 This is needed on terminals on which EL is not supported.
944 It is otherwise useful on terminals
945 for which the @code{back_color_erase}
946 (@code{bce}) boolean @code{terminfo} capability does not apply,
947 when the chosen highlight colors do not affect the background,
948 or when EL is too slow or causes too much flicker.
949 The default is false (i.e., the capability is omitted).
952 Note that boolean capabilities have no @samp{=}... part.
953 They are omitted (i.e., false) by default and become true when specified.
959 @vindex LC_ALL @r{environment variable}
960 @vindex LC_COLLATE @r{environment variable}
961 @vindex LANG @r{environment variable}
962 @cindex character type
963 @cindex national language support
965 These variables specify the locale for the @code{LC_COLLATE} category,
966 which might affect how range expressions like @samp{[a-z]} are
972 @vindex LC_ALL @r{environment variable}
973 @vindex LC_CTYPE @r{environment variable}
974 @vindex LANG @r{environment variable}
975 These variables specify the locale for the @code{LC_CTYPE} category,
976 which determines the type of characters,
977 e.g., which characters are whitespace.
982 @vindex LC_ALL @r{environment variable}
983 @vindex LC_MESSAGES @r{environment variable}
984 @vindex LANG @r{environment variable}
985 @cindex language of messages
986 @cindex message language
987 @cindex national language support
988 @cindex translation of message language
989 These variables specify the locale for the @code{LC_MESSAGES} category,
990 which determines the language that @command{grep} uses for messages.
991 The default @samp{C} locale uses American English messages.
993 @item POSIXLY_CORRECT
994 @vindex POSIXLY_CORRECT @r{environment variable}
995 If set, @command{grep} behaves as POSIX requires; otherwise,
996 @command{grep} behaves more like other GNU programs.
998 requires that options that
999 follow file names must be treated as file names;
1001 such options are permuted to the front of the operand list
1002 and are treated as options.
1003 Also, @code{POSIXLY_CORRECT} disables special handling of an
1004 invalid bracket expression. @xref{invalid-bracket-expr}.
1006 @item _@var{N}_GNU_nonoption_argv_flags_
1007 @vindex _@var{N}_GNU_nonoption_argv_flags_ @r{environment variable}
1008 (Here @code{@var{N}} is @command{grep}'s numeric process ID.)
1009 If the @var{i}th character of this environment variable's value is @samp{1},
1010 do not consider the @var{i}th operand of @command{grep} to be an option,
1011 even if it appears to be one.
1012 A shell can put this variable in the environment for each command it runs,
1013 specifying which operands are the results of file name wildcard expansion
1014 and therefore should not be treated as options.
1015 This behavior is available only with the GNU C library,
1016 and only when @code{POSIXLY_CORRECT} is not set.
1022 @section Exit Status
1024 @cindex return status
1026 Normally, the exit status is 0 if selected lines are found and 1 otherwise.
1027 But the exit status is 2 if an error occurred, unless the @option{-q} or
1028 @option{--quiet} or @option{--silent} option is used and a selected line
1030 Note, however, that POSIX only mandates,
1031 for programs such as @command{grep}, @command{cmp}, and @command{diff},
1032 that the exit status in case of error be greater than 1;
1033 it is therefore advisable, for the sake of portability,
1034 to use logic that tests for this general condition
1035 instead of strict equality with@ 2.
1039 @section @command{grep} Programs
1040 @cindex @command{grep} programs
1041 @cindex variants of @command{grep}
1043 @command{grep} searches the named input files
1044 for lines containing a match to the given pattern.
1045 By default, @command{grep} prints the matching lines.
1046 A file named @file{-} stands for standard input.
1047 If no input is specified, @command{grep} searches the working
1048 directory @file{.} if given a command-line option specifying
1049 recursion; otherwise, @command{grep} searches standard input.
1050 There are four major variants of @command{grep},
1051 controlled by the following options.
1056 @itemx --basic-regexp
1058 @opindex --basic-regexp
1059 @cindex matching basic regular expressions
1060 Interpret the pattern as a basic regular expression (BRE).
1061 This is the default.
1064 @itemx --extended-regexp
1066 @opindex --extended-regexp
1067 @cindex matching extended regular expressions
1068 Interpret the pattern as an extended regular expression (ERE).
1069 (@option{-E} is specified by POSIX.)
1072 @itemx --fixed-strings
1074 @opindex --fixed-strings
1075 @cindex matching fixed strings
1076 Interpret the pattern as a list of fixed strings, separated
1077 by newlines, any of which is to be matched.
1078 (@option{-F} is specified by POSIX.)
1081 @itemx --perl-regexp
1083 @opindex --perl-regexp
1084 @cindex matching Perl regular expressions
1085 Interpret the pattern as a Perl regular expression.
1086 This is highly experimental and
1087 @samp{grep@ -P} may warn of unimplemented features.
1092 two variant programs @command{egrep} and @command{fgrep} are available.
1093 @command{egrep} is the same as @samp{grep@ -E}.
1094 @command{fgrep} is the same as @samp{grep@ -F}.
1095 Direct invocation as either
1096 @command{egrep} or @command{fgrep} is deprecated,
1097 but is provided to allow historical applications
1098 that rely on them to run unmodified.
1101 @node Regular Expressions
1102 @chapter Regular Expressions
1103 @cindex regular expressions
1105 A @dfn{regular expression} is a pattern that describes a set of strings.
1106 Regular expressions are constructed analogously to arithmetic expressions,
1107 by using various operators to combine smaller expressions.
1108 @command{grep} understands
1109 three different versions of regular expression syntax:
1110 ``basic,'' (BRE) ``extended'' (ERE) and ``perl''.
1111 In GNU @command{grep},
1112 there is no difference in available functionality between the basic and
1114 In other implementations, basic regular expressions are less powerful.
1115 The following description applies to extended regular expressions;
1116 differences for basic regular expressions are summarized afterwards.
1117 Perl regular expressions give additional functionality, and are
1118 documented in the @i{pcresyntax}(3) and @i{pcrepattern}(3) manual pages,
1119 but may not be available on every system.
1122 * Fundamental Structure::
1123 * Character Classes and Bracket Expressions::
1124 * The Backslash Character and Special Expressions::
1126 * Back-references and Subexpressions::
1127 * Basic vs Extended::
1130 @node Fundamental Structure
1131 @section Fundamental Structure
1133 The fundamental building blocks are the regular expressions that match
1135 Most characters, including all letters and digits,
1136 are regular expressions that match themselves.
1138 with special meaning may be quoted by preceding it with a backslash.
1140 A regular expression may be followed by one of several
1141 repetition operators:
1149 The period @samp{.} matches any single character.
1153 @cindex question mark
1154 @cindex match expression at most once
1155 The preceding item is optional and will be matched at most once.
1160 @cindex match expression zero or more times
1161 The preceding item will be matched zero or more times.
1166 @cindex match expression one or more times
1167 The preceding item will be matched one or more times.
1170 @opindex @{@var{n}@}
1171 @cindex braces, one argument
1172 @cindex match expression @var{n} times
1173 The preceding item is matched exactly @var{n} times.
1176 @opindex @{@var{n},@}
1177 @cindex braces, second argument omitted
1178 @cindex match expression @var{n} or more times
1179 The preceding item is matched @var{n} or more times.
1182 @opindex @{,@var{m}@}
1183 @cindex braces, first argument omitted
1184 @cindex match expression at most @var{m} times
1185 The preceding item is matched at most @var{m} times.
1186 This is a GNU extension.
1188 @item @{@var{n},@var{m}@}
1189 @opindex @{@var{n},@var{m}@}
1190 @cindex braces, two arguments
1191 @cindex match expression from @var{n} to @var{m} times
1192 The preceding item is matched at least @var{n} times, but not more than
1197 The empty regular expression matches the empty string.
1198 Two regular expressions may be concatenated;
1199 the resulting regular expression
1200 matches any string formed by concatenating two substrings
1201 that respectively match the concatenated expressions.
1203 Two regular expressions may be joined by the infix operator @samp{|};
1204 the resulting regular expression
1205 matches any string matching either alternate expression.
1207 Repetition takes precedence over concatenation,
1208 which in turn takes precedence over alternation.
1209 A whole expression may be enclosed in parentheses
1210 to override these precedence rules and form a subexpression.
1212 @node Character Classes and Bracket Expressions
1213 @section Character Classes and Bracket Expressions
1215 @cindex bracket expression
1216 @cindex character class
1217 A @dfn{bracket expression} is a list of characters enclosed by @samp{[} and
1219 It matches any single character in that list;
1220 if the first character of the list is the caret @samp{^},
1221 then it matches any character @strong{not} in the list.
1222 For example, the regular expression
1223 @samp{[0123456789]} matches any single digit.
1225 @cindex range expression
1226 Within a bracket expression, a @dfn{range expression} consists of two
1227 characters separated by a hyphen.
1228 It matches any single character that
1229 sorts between the two characters, inclusive.
1230 In the default C locale, the sorting sequence is the native character
1231 order; for example, @samp{[a-d]} is equivalent to @samp{[abcd]}.
1232 In other locales, the sorting sequence is not specified, and
1233 @samp{[a-d]} might be equivalent to @samp{[abcd]} or to
1234 @samp{[aBbCcDd]}, or it might fail to match any character, or the set of
1235 characters that it matches might even be erratic.
1236 To obtain the traditional interpretation
1237 of bracket expressions, you can use the @samp{C} locale by setting the
1238 @env{LC_ALL} environment variable to the value @samp{C}.
1240 Finally, certain named classes of characters are predefined within
1241 bracket expressions, as follows.
1242 Their interpretation depends on the @code{LC_CTYPE} locale;
1243 for example, @samp{[[:alnum:]]} means the character class of numbers and letters
1244 in the current locale.
1246 @cindex classes of characters
1247 @cindex character classes
1251 @opindex alnum @r{character class}
1252 @cindex alphanumeric characters
1253 Alphanumeric characters:
1254 @samp{[:alpha:]} and @samp{[:digit:]}; in the @samp{C} locale and ASCII character encoding, this is the same as @samp{[0-9A-Za-z]}.
1257 @opindex alpha @r{character class}
1258 @cindex alphabetic characters
1259 Alphabetic characters:
1260 @samp{[:lower:]} and @samp{[:upper:]}; in the @samp{C} locale and ASCII character encoding, this is the same as @samp{[A-Za-z]}.
1263 @opindex blank @r{character class}
1264 @cindex blank characters
1269 @opindex cntrl @r{character class}
1270 @cindex control characters
1272 In ASCII, these characters have octal codes 000
1273 through 037, and 177 (@code{DEL}).
1274 In other character sets, these are
1275 the equivalent characters, if any.
1278 @opindex digit @r{character class}
1279 @cindex digit characters
1280 @cindex numeric characters
1281 Digits: @code{0 1 2 3 4 5 6 7 8 9}.
1284 @opindex graph @r{character class}
1285 @cindex graphic characters
1286 Graphical characters:
1287 @samp{[:alnum:]} and @samp{[:punct:]}.
1290 @opindex lower @r{character class}
1291 @cindex lower-case letters
1292 Lower-case letters; in the @samp{C} locale and ASCII character
1294 @code{a b c d e f g h i j k l m n o p q r s t u v w x y z}.
1297 @opindex print @r{character class}
1298 @cindex printable characters
1299 Printable characters:
1300 @samp{[:alnum:]}, @samp{[:punct:]}, and space.
1303 @opindex punct @r{character class}
1304 @cindex punctuation characters
1305 Punctuation characters; in the @samp{C} locale and ASCII character
1307 @code{!@: " # $ % & ' ( ) * + , - .@: / : ; < = > ?@: @@ [ \ ] ^ _ ` @{ | @} ~}.
1310 @opindex space @r{character class}
1311 @cindex space characters
1312 @cindex whitespace characters
1313 Space characters: in the @samp{C} locale, this is
1314 tab, newline, vertical tab, form feed, carriage return, and space.
1315 @xref{Usage}, for more discussion of matching newlines.
1318 @opindex upper @r{character class}
1319 @cindex upper-case letters
1320 Upper-case letters: in the @samp{C} locale and ASCII character
1322 @code{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}.
1325 @opindex xdigit @r{character class}
1326 @cindex xdigit class
1327 @cindex hexadecimal digits
1329 @code{0 1 2 3 4 5 6 7 8 9 A B C D E F a b c d e f}.
1332 Note that the brackets in these class names are
1333 part of the symbolic names, and must be included in addition to
1334 the brackets delimiting the bracket expression.
1336 @anchor{invalid-bracket-expr}
1337 If you mistakenly omit the outer brackets, and search for say, @samp{[:upper:]},
1338 GNU @command{grep} prints a diagnostic and exits with status 2, on
1339 the assumption that you did not intend to search for the nominally
1340 equivalent regular expression: @samp{[:epru]}.
1341 Set the @code{POSIXLY_CORRECT} environment variable to disable this feature.
1343 Most meta-characters lose their special meaning inside bracket expressions.
1347 ends the bracket expression if it's not the first list item.
1348 So, if you want to make the @samp{]} character a list item,
1349 you must put it first.
1352 represents the open collating symbol.
1355 represents the close collating symbol.
1358 represents the open equivalence class.
1361 represents the close equivalence class.
1364 represents the open character class symbol, and should be followed by a valid character class name.
1367 represents the close character class symbol.
1370 represents the range if it's not first or last in a list or the ending point
1374 represents the characters not in the list.
1375 If you want to make the @samp{^}
1376 character a list item, place it anywhere but first.
1380 @node The Backslash Character and Special Expressions
1381 @section The Backslash Character and Special Expressions
1384 The @samp{\} character,
1385 when followed by certain ordinary characters,
1386 takes a special meaning:
1391 Match the empty string at the edge of a word.
1394 Match the empty string provided it's not at the edge of a word.
1397 Match the empty string at the beginning of word.
1400 Match the empty string at the end of word.
1403 Match word constituent, it is a synonym for @samp{[_[:alnum:]]}.
1406 Match non-word constituent, it is a synonym for @samp{[^_[:alnum:]]}.
1409 Match whitespace, it is a synonym for @samp{[[:space:]]}.
1412 Match non-whitespace, it is a synonym for @samp{[^[:space:]]}.
1416 For example, @samp{\brat\b} matches the separate word @samp{rat},
1417 @samp{\Brat\B} matches @samp{crate} but not @samp{furry rat}.
1423 The caret @samp{^} and the dollar sign @samp{$} are meta-characters that
1424 respectively match the empty string at the beginning and end of a line.
1425 They are termed @dfn{anchors}, since they force the match to be ``anchored''
1426 to beginning or end of a line, respectively.
1428 @node Back-references and Subexpressions
1429 @section Back-references and Subexpressions
1430 @cindex subexpression
1431 @cindex back-reference
1433 The back-reference @samp{\@var{n}}, where @var{n} is a single digit, matches
1434 the substring previously matched by the @var{n}th parenthesized subexpression
1435 of the regular expression.
1436 For example, @samp{(a)\1} matches @samp{aa}.
1437 When used with alternation, if the group does not participate in the match then
1438 the back-reference makes the whole match fail.
1439 For example, @samp{a(.)|b\1}
1440 will not match @samp{ba}.
1441 When multiple regular expressions are given with
1442 @option{-e} or from a file (@samp{-f @var{file}}),
1443 back-references are local to each expression.
1445 @node Basic vs Extended
1446 @section Basic vs Extended Regular Expressions
1447 @cindex basic regular expressions
1449 In basic regular expressions the meta-characters @samp{?}, @samp{+},
1450 @samp{@{}, @samp{|}, @samp{(}, and @samp{)} lose their special meaning;
1451 instead use the backslashed versions @samp{\?}, @samp{\+}, @samp{\@{},
1452 @samp{\|}, @samp{\(}, and @samp{\)}.
1454 @cindex interval specifications
1455 Traditional @command{egrep} did not support the @samp{@{} meta-character,
1456 and some @command{egrep} implementations support @samp{\@{} instead, so
1457 portable scripts should avoid @samp{@{} in @samp{grep@ -E} patterns and
1458 should use @samp{[@{]} to match a literal @samp{@{}.
1460 GNU @command{grep@ -E} attempts to support traditional usage by
1461 assuming that @samp{@{} is not special if it would be the start of an
1462 invalid interval specification.
1463 For example, the command
1464 @samp{grep@ -E@ '@{1'} searches for the two-character string @samp{@{1}
1465 instead of reporting a syntax error in the regular expression.
1466 POSIX allows this behavior as an extension, but portable scripts
1473 @cindex usage, examples
1474 Here is an example command that invokes GNU @command{grep}:
1477 grep -i 'hello.*world' menu.h main.c
1481 This lists all lines in the files @file{menu.h} and @file{main.c} that
1482 contain the string @samp{hello} followed by the string @samp{world};
1483 this is because @samp{.*} matches zero or more characters within a line.
1484 @xref{Regular Expressions}.
1485 The @option{-i} option causes @command{grep}
1486 to ignore case, causing it to match the line @samp{Hello, world!}, which
1487 it would not otherwise match.
1488 @xref{Invoking}, for more details about
1489 how to invoke @command{grep}.
1491 @cindex using @command{grep}, Q&A
1492 @cindex FAQ about @command{grep} usage
1493 Here are some common questions and answers about @command{grep} usage.
1498 How can I list just the names of matching files?
1505 lists the names of all C files in the current directory whose contents
1506 mention @samp{main}.
1509 How do I search directories recursively?
1512 grep -r 'hello' /home/gigi
1516 searches for @samp{hello} in all files
1517 under the @file{/home/gigi} directory.
1518 For more control over which files are searched,
1519 use @command{find}, @command{grep}, and @command{xargs}.
1520 For example, the following command searches only C files:
1523 find /home/gigi -name '*.c' -print0 | xargs -0r grep -H 'hello'
1526 This differs from the command:
1532 which merely looks for @samp{hello} in all files in the current
1533 directory whose names end in @samp{.c}.
1534 The @samp{find ...} command line above is more similar to the command:
1537 grep -rH --include='*.c' 'hello' /home/gigi
1541 What if a pattern has a leading @samp{-}?
1544 grep -e '--cut here--' *
1548 searches for all lines matching @samp{--cut here--}.
1549 Without @option{-e},
1550 @command{grep} would attempt to parse @samp{--cut here--} as a list of
1554 Suppose I want to search for a whole word, not a part of a word?
1561 searches only for instances of @samp{hello} that are entire words;
1562 it does not match @samp{Othello}.
1563 For more control, use @samp{\<} and
1564 @samp{\>} to match the start and end of words.
1572 searches only for words ending in @samp{hello}, so it matches the word
1576 How do I output context around the matching lines?
1583 prints two lines of context around each matching line.
1586 How do I force @command{grep} to print the name of the file?
1588 Append @file{/dev/null}:
1591 grep 'eli' /etc/passwd /dev/null
1597 /etc/passwd:eli:x:2098:1000:Eli Smith:/home/eli:/bin/bash
1600 Alternatively, use @option{-H}, which is a GNU extension:
1603 grep -H 'eli' /etc/passwd
1607 Why do people use strange regular expressions on @command{ps} output?
1610 ps -ef | grep '[c]ron'
1613 If the pattern had been written without the square brackets, it would
1614 have matched not only the @command{ps} output line for @command{cron},
1615 but also the @command{ps} output line for @command{grep}.
1616 Note that on some platforms,
1617 @command{ps} limits the output to the width of the screen;
1618 @command{grep} does not have any limit on the length of a line
1619 except the available memory.
1622 Why does @command{grep} report ``Binary file matches''?
1624 If @command{grep} listed all matching ``lines'' from a binary file, it
1625 would probably generate output that is not useful, and it might even
1626 muck up your display.
1627 So GNU @command{grep} suppresses output from
1628 files that appear to be binary files.
1629 To force GNU @command{grep}
1630 to output lines even from files that appear to be binary, use the
1631 @option{-a} or @samp{--binary-files=text} option.
1633 ``Binary file matches'' messages, use the @option{-I} or
1634 @samp{--binary-files=without-match} option.
1637 Why doesn't @samp{grep -lv} print non-matching file names?
1639 @samp{grep -lv} lists the names of all files containing one or more
1640 lines that do not match.
1641 To list the names of all files that contain no
1642 matching lines, use the @option{-L} or @option{--files-without-match}
1646 I can do ``OR'' with @samp{|}, but what about ``AND''?
1649 grep 'paul' /etc/motd | grep 'franc,ois'
1653 finds all lines that contain both @samp{paul} and @samp{franc,ois}.
1656 Why does the empty pattern match every input line?
1658 The @command{grep} command searches for lines that contain strings
1659 that match a pattern. Every line contains the empty string, so an
1660 empty pattern causes @command{grep} to find a match on each line. It
1661 is not the only such pattern: @samp{^}, @samp{$}, @samp{.*}, and many
1662 other patterns cause @command{grep} to match every line.
1664 To match empty lines, use the pattern @samp{^$}. To match blank
1665 lines, use the pattern @samp{^[[:blank:]]*$}. To match no lines at
1666 all, use the command @samp{grep -f /dev/null}.
1669 How can I search in both standard input and in files?
1671 Use the special file name @samp{-}:
1674 cat /etc/passwd | grep 'alain' - /etc/motd
1679 How to express palindromes in a regular expression?
1681 It can be done by using back-references;
1683 a palindrome of 4 characters can be written with a BRE:
1686 grep -w -e '\(.\)\(.\).\2\1' file
1689 It matches the word ``radar'' or ``civic.''
1691 Guglielmo Bondioni proposed a single RE
1692 that finds all palindromes up to 19 characters long
1693 using @w{9 subexpressions} and @w{9 back-references}:
1696 grep -E -e '^(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?).?\9\8\7\6\5\4\3\2\1$' file
1699 Note this is done by using GNU ERE extensions;
1700 it might not be portable to other implementations of @command{grep}.
1703 Why is this back-reference failing?
1706 echo 'ba' | grep -E '(a)\1|b\1'
1709 This gives no output, because the first alternate @samp{(a)\1} does not match,
1710 as there is no @samp{aa} in the input, so the @samp{\1} in the second alternate
1711 has nothing to refer back to, meaning it will never match anything.
1712 (The second alternate in this example can only match
1713 if the first alternate has matched---making the second one superfluous.)
1716 How can I match across lines?
1718 Standard grep cannot do this, as it is fundamentally line-based.
1719 Therefore, merely using the @code{[:space:]} character class does not
1720 match newlines in the way you might expect.
1722 With the GNU @command{grep} option @code{-z} (@pxref{File and
1723 Directory Selection}), the input is terminated by null bytes. Thus,
1724 you can match newlines in the input, but typically if there is a match
1725 the entire input is output, so this usage is often combined with
1726 output-suppressing options like @option{-q}, e.g.:
1729 printf 'foo\nbar\n' | grep -z -q 'foo[[:space:]]\+bar'
1732 If this does not suffice, you can transform the input
1733 before giving it to @command{grep}, or turn to @command{awk},
1734 @command{sed}, @command{perl}, or many other utilities that are
1735 designed to operate across lines.
1738 What do @command{grep}, @command{fgrep}, and @command{egrep} stand for?
1740 The name @command{grep} comes from the way line editing was done on Unix.
1742 @command{ed} uses the following syntax
1743 to print a list of matching lines on the screen:
1746 global/regular expression/print
1750 @command{fgrep} stands for Fixed @command{grep};
1751 @command{egrep} stands for Extended @command{grep}.
1756 @node Reporting Bugs
1757 @chapter Reporting bugs
1759 @cindex bugs, reporting
1760 Email bug reports to @email{bug-grep@@gnu.org},
1761 a mailing list whose web page is
1762 @url{http://lists.gnu.org/mailman/listinfo/bug-grep}.
1763 The Savannah bug tracker for @command{grep} is located at
1764 @url{http://savannah.gnu.org/bugs/?group=grep}.
1769 Large repetition counts in the @samp{@{n,m@}} construct may cause
1770 @command{grep} to use lots of memory.
1771 In addition, certain other
1772 obscure regular expressions require exponential time and
1773 space, and may cause @command{grep} to run out of memory.
1775 Back-references are very slow, and may require exponential time.
1782 GNU @command{grep} is licensed under the GNU GPL, which makes it @dfn{free
1785 The ``free'' in ``free software'' refers to liberty, not price. As
1786 some GNU project advocates like to point out, think of ``free speech''
1787 rather than ``free beer''. In short, you have the right (freedom) to
1788 run and change @command{grep} and distribute it to other people, and---if you
1789 want---charge money for doing either. The important restriction is
1790 that you have to grant your recipients the same rights and impose the
1793 This general method of licensing software is sometimes called
1794 @dfn{open source}. The GNU project prefers the term ``free software''
1795 for reasons outlined at
1796 @url{http://www.gnu.org/philosophy/open-source-misses-the-point.html}.
1798 This manual is free documentation in the same sense. The
1799 documentation license is included below. The license for the program
1800 is available with the source code, or at
1801 @url{http://www.gnu.org/licenses/gpl.html}.
1804 * GNU Free Documentation License::
1807 @node GNU Free Documentation License
1808 @section GNU Free Documentation License