1 @c $DragonFly: src/gnu/usr.bin/grep/doc/grep.texi,v 1.2 2005/10/08 11:28:23 corecode Exp $
3 \input texinfo @c -*-texinfo-*-
6 @settitle grep, print lines matching a pattern
9 @c This file has the new style title page commands.
10 @c Run `makeinfo' rather than `texinfo-format-buffer'.
31 * grep: (grep). print lines matching a pattern.
33 This file documents @command{grep}, a pattern matching engine.
36 Published by the Free Software Foundation,
37 59 Temple Place - Suite 330
38 Boston, MA 02111-1307, USA
40 Copyright 1999 Free Software Foundation, Inc.
42 Permission is granted to make and distribute verbatim copies of
43 this manual provided the copyright notice and this permission notice
44 are preserved on all copies.
47 Permission is granted to process this file through TeX and print the
48 results, provided the printed document carries copying permission
49 notice identical to this one except for the removal of this paragraph
50 (this paragraph not being relevant to the printed manual).
53 Permission is granted to copy and distribute modified versions of this
54 manual under the conditions for verbatim copying, provided that the entire
55 resulting derived work is distributed under the terms of a permission
56 notice identical to this one.
58 Permission is granted to copy and distribute translations of this manual
59 into another language, under the above conditions for modified versions,
60 except that this permission notice may be stated in a translation approved
64 @setchapternewpage off
67 @title grep, searching for a pattern
68 @subtitle version @value{VERSION}, @value{UPDATED}
69 @author Alain Magloire et al.
72 @vskip 0pt plus 1filll
73 Copyright @copyright{} 1999 Free Software Foundation, Inc.
76 Published by the Free Software Foundation, @*
77 59 Temple Place - Suite 330, @*
78 Boston, MA 02111-1307, USA
80 Permission is granted to make and distribute verbatim copies of
81 this manual provided the copyright notice and this permission notice
82 are preserved on all copies.
84 Permission is granted to copy and distribute modified versions of this
85 manual under the conditions for verbatim copying, provided that the entire
86 resulting derived work is distributed under the terms of a permission
87 notice identical to this one.
89 Permission is granted to copy and distribute translations of this manual
90 into another language, under the above conditions for modified versions,
91 except that this permission notice may be stated in a translation approved
102 @command{grep} searches for lines matching a pattern.
104 This document was produced for version @value{VERSION} of @sc{gnu}
109 * Introduction:: Introduction.
110 * Invoking:: Invoking @command{grep}; description of options.
111 * Diagnostics:: Exit status returned by @command{grep}.
112 * Grep Programs:: @command{grep} programs.
113 * Regular Expressions:: Regular Expressions.
115 * Reporting Bugs:: Reporting Bugs.
116 * Concept Index:: A menu with all the topics in this manual.
117 * Index:: A menu with all @command{grep} commands
118 and command-line options.
123 @chapter Introduction
125 @cindex Searching for a pattern.
127 @command{grep} searches the input files
128 for lines containing a match to a given
129 pattern list. When it finds a match in a line, it copies the line to standard
130 output (by default), or does whatever other sort of output you have requested
133 Though @command{grep} expects to do the matching on text,
134 it has no limits on input line length other than available memory,
135 and it can match arbitrary characters within a line.
136 If the final byte of an input file is not a newline,
137 @command{grep} silently supplies one.
138 Since newline is also a separator for the list of patterns, there
139 is no way to match newline characters in a text.
142 @chapter Invoking @command{grep}
144 @command{grep} comes with a rich set of options from @sc{posix.2} and @sc{gnu}
153 @cindex counting lines
154 Suppress normal output; instead print a count of matching
155 lines for each input file. With the @samp{-v}, @samp{--invert-match} option,
156 count non-matching lines.
158 @item -e @var{pattern}
159 @itemx --regexp=@var{pattern}
161 @opindex --regexp=@var{pattern}
163 Use @var{pattern} as the pattern; useful to protect patterns
164 beginning with a @samp{-}.
167 @itemx --file=@var{file}
170 @cindex pattern from file
171 Obtain patterns from @var{file}, one per line. The empty
172 file contains zero patterns, and therefore matches nothing.
177 @opindex --ignore-case
178 @cindex case insensitive search
179 Ignore case distinctions in both the pattern and the input files.
182 @itemx --files-with-matches
184 @opindex --files-with-matches
185 @cindex names of matching files
186 Suppress normal output; instead print the name of each input
187 file from which output would normally have been printed.
188 The scanning of every file will stop on the first match.
193 @opindex --line-number
194 @cindex line numbering
195 Prefix each line of output with the line number within its input file.
203 @cindex quiet, silent
204 Quiet; suppress normal output. The scanning of every file will stop on
205 the first match. Also see the @samp{-s} or @samp{--no-messages} option.
210 @opindex --no-messages
211 @cindex suppress error messages
212 Suppress error messages about nonexistent or unreadable files.
213 Portability note: unlike @sc{gnu} @command{grep}, traditional
214 @command{grep} did not conform to @sc{posix.2}, because traditional
215 @command{grep} lacked a @samp{-q} option and its @samp{-s} option behaved
216 like @sc{gnu} @command{grep}'s @samp{-q} option. Shell scripts intended
217 to be portable to traditional @command{grep} should avoid both
218 @samp{-q} and @samp{-s} and should redirect
219 output to @file{/dev/null} instead.
222 @itemx --invert-match
224 @opindex --invert-match
225 @cindex invert matching
226 @cindex print non-matching lines
227 Invert the sense of matching, to select non-matching lines.
232 @opindex --line-regexp
233 @cindex match the whole line
234 Select only those matches that exactly match the whole line.
238 @section (@sc{gnu}) Extensions
243 @itemx --after-context=@var{num}
245 @opindex --after-context
246 @cindex after context
247 @cindex context lines, after match
248 Print @var{num} lines of trailing context after matching lines.
251 @itemx --before-context=@var{num}
253 @opindex --before-context
254 @cindex before context
255 @cindex context lines, before match
256 Print @var{num} lines of leading context before matching lines.
259 @itemx --context=[@var{num}]
263 Print @var{num} lines (default 2) of output context.
268 Same as @samp{--context=@var{num}} lines of leading and trailing
269 context. However, grep will never print any given line more than once.
276 @cindex Version, printing
277 Print the version number of @command{grep} to the standard output stream.
278 This version number should be included in all bug reports.
282 @cindex Usage summary, printing
283 Print a usage message briefly summarizing these command-line options
284 and the bug-reporting address, then exit.
286 @itemx --binary-files=@var{type}
287 @opindex --binary-files
289 If the first few bytes of a file indicate that the file contains binary
290 data, assume that the file is of type @var{type}. By default,
291 @var{type} is @samp{binary}, and @command{grep} normally outputs either
292 a one-line message saying that a binary file matches, or no message if
293 there is no match. If @var{type} is @samp{without-match},
294 @command{grep} assumes that a binary file does not match;
295 this is equivalent to the @samp{-I} option. If @var{type}
296 is @samp{text}, @command{grep} processes a binary file as if it were
297 text; this is equivalent to the @samp{-a} option.
298 @emph{Warning:} @samp{--binary-files=text} might output binary garbage,
299 which can have nasty side effects if the output is a terminal and if the
300 terminal driver interprets some of it as commands.
305 @opindex --byte-offset
307 Print the byte offset within the input file before each line of output.
308 When @command{grep} runs on @sc{ms-dos} or MS-Windows, the printed
310 depend on whether the @samp{-u} (@samp{--unix-byte-offsets}) option is
313 @item -d @var{action}
314 @itemx --directories=@var{action}
316 @opindex --directories
317 @cindex directory search
318 If an input file is a directory, use @var{action} to process it.
319 By default, @var{action} is @samp{read}, which means that directories are
320 read just as if they were ordinary files (some operating systems
321 and filesystems disallow this, and will cause @command{grep} to print error
322 messages for every directory). If @var{action} is @samp{skip},
323 directories are silently skipped. If @var{action} is @samp{recurse},
324 @command{grep} reads all files under each directory, recursively; this is
325 equivalent to the @samp{-r} option.
328 @itemx --with-filename
330 @opindex --With-filename
331 @cindex with filename prefix
332 Print the filename for each match.
337 @opindex --no-filename
338 @cindex no filename prefix
339 Suppress the prefixing of filenames on output when multiple files are searched.
342 @itemx --files-without-match
344 @opindex --files-without-match
345 @cindex files which don't match
346 Suppress normal output; instead print the name of each input
347 file from which no output would normally have been printed.
348 The scanning of every file will stop on the first match.
354 @cindex suppress binary data
356 Process a binary file as if it were text; this is equivalent to the
357 @samp{--binary-files=text} option.
360 Process a binary file as if it did not contain matching data; this is
361 equivalent to the @samp{--binary-files=without-match} option.
366 @opindex --word-regexp
367 @cindex matching whole words
368 Select only those lines containing matches that form
369 whole words. The test is that the matching substring
370 must either be at the beginning of the line, or preceded
371 by a non-word constituent character. Similarly,
372 it must be either at the end of the line or followed by
373 a non-word constituent character. Word-constituent
374 characters are letters, digits, and the underscore.
380 @cindex recursive search
381 @cindex searching directory trees
382 For each directory mentioned in the command line, read and process all
383 files in that directory, recursively. This is the same as the @samp{-d
389 @opindex --only-files
390 @cindex ignoring special files
391 @cindex ignoring symlinked directories
392 Ignore all special files, except for symlinks.
393 When recursing into directories, ignore symlinked directories as well.
397 @cindex case insensitive search, obsolete option
398 Obsolete synonym for @samp{-i}.
404 @cindex DOS/Windows binary files
405 @cindex binary files, DOS/Windows
406 Treat the file(s) as binary. By default, under @sc{ms-dos}
407 and MS-Windows, @command{grep} guesses the file type by looking
408 at the contents of the first 32kB read from the file.
409 If @command{grep} decides the file is a text file, it strips the
410 @code{CR} characters from the original file contents (to make
411 regular expressions with @code{^} and @code{$} work correctly).
412 Specifying @samp{-U} overrules this guesswork, causing all
413 files to be read and passed to the matching mechanism
414 verbatim; if the file is a text file with @code{CR/LF} pairs
415 at the end of each line, this will cause some regular
416 expressions to fail. This option has no effect on platforms other than
417 @sc{ms-dos} and MS-Windows.
420 @itemx --unix-byte-offsets
422 @opindex --unix-byte-offsets
423 @cindex DOS byte offsets
424 @cindex byte offsets, on DOS/Windows
425 Report Unix-style byte offsets. This switch causes
426 @command{grep} to report byte offsets as if the file were Unix style
427 text file, i.e., the byte offsets ignore the @code{CR} characters which were
428 stripped. This will produce results identical to running @command{grep} on
429 a Unix machine. This option has no effect unless @samp{-b}
430 option is also used; it has no effect on platforms other than @sc{ms-dos} and
435 @cindex memory mapped input
436 If possible, use the @code{mmap} system call to read input, instead of
437 the default @code{read} system call. In some situations, @samp{--mmap}
438 yields better performance. However, @samp{--mmap} can cause undefined
439 behavior (including core dumps) if an input file shrinks while
440 @command{grep} is operating, or if an I/O error occurs.
446 @cindex zero-terminated file names
447 Output a zero byte (the @sc{ascii} @code{NUL} character) instead of the
448 character that normally follows a file name. For example, @samp{grep
449 -lZ} outputs a zero byte after each file name instead of the usual
450 newline. This option makes the output unambiguous, even in the presence
451 of file names containing unusual characters like newlines. This option
452 can be used with commands like @samp{find -print0}, @samp{perl -0},
453 @samp{sort -z}, and @samp{xargs -0} to process arbitrary file names,
454 even those that contain newline characters.
460 @cindex zero-terminated lines
461 Treat the input as a set of lines, each terminated by a zero byte (the
462 @sc{ascii} @code{NUL} character) instead of a newline. Like the @samp{-Z}
463 or @samp{--null} option, this option can be used with commands like
464 @samp{sort -z} to process arbitrary file names.
468 Several additional options control which variant of the @command{grep}
469 matching engine is used. @xref{Grep Programs}.
471 @section Environment Variables
473 Grep's behavior is affected by the following environment variables.
474 @cindex environment variables
480 @cindex default options environment variable
481 This variable specifies default options to be placed in front of any
482 explicit options. For example, if @code{GREP_OPTIONS} is
483 @samp{--binary-files=without-match --directories=skip}, @command{grep}
484 behaves as if the two options @samp{--binary-files=without-match} and
485 @samp{--directories=skip} had been specified before
486 any explicit options. Option specifications are separated by
487 whitespace. A backslash escapes the next character, so it can be used to
488 specify an option containing whitespace or a backslash.
496 @cindex language of messages
497 @cindex message language
498 @cindex national language support
500 @cindex translation of message language
501 These variables specify the @code{LC_MESSAGES} locale, which determines
502 the language that @command{grep} uses for messages. The locale is determined
503 by the first of these variables that is set. American English is used
504 if none of these environment variables are set, or if the message
505 catalog is not installed, or if @command{grep} was not compiled with national
506 language support (@sc{nls}).
514 @cindex character type
515 @cindex national language support
517 These variables specify the @code{LC_CTYPE} locale, which determines the
518 type of characters, e.g., which characters are whitespace. The locale is
519 determined by the first of these variables that is set. The @sc{posix}
520 locale is used if none of these environment variables are set, or if the
521 locale catalog is not installed, or if @command{grep} was not compiled with
522 national language support (@sc{nls}).
524 @item POSIXLY_CORRECT
525 @vindex POSIXLY_CORRECT
526 If set, @command{grep} behaves as @sc{posix.2} requires; otherwise,
527 @command{grep} behaves more like other @sc{gnu} programs. @sc{posix.2}
528 requires that options that
529 follow file names must be treated as file names; by default, such
530 options are permuted to the front of the operand list and are treated as
531 options. Also, @sc{posix.2} requires that unrecognized options be
533 ``illegal'', but since they are not really against the law the default
534 is to diagnose them as ``invalid''. @code{POSIXLY_CORRECT} also
535 disables @code{_@var{N}_GNU_nonoption_argv_flags_}, described below.
537 @item _@var{N}_GNU_nonoption_argv_flags_
538 @vindex _@var{N}_GNU_nonoption_argv_flags_
539 (Here @code{@var{N}} is @command{grep}'s numeric process ID.) If the
540 @var{i}th character of this environment variable's value is @samp{1}, do
541 not consider the @var{i}th operand of @command{grep} to be an option, even if
542 it appears to be one. A shell can put this variable in the environment
543 for each command it runs, specifying which operands are the results of
544 file name wildcard expansion and therefore should not be treated as
545 options. This behavior is available only with the @sc{gnu} C library, and
546 only when @code{POSIXLY_CORRECT} is not set.
553 Normally, exit status is 0 if matches were found, and 1 if no matches
554 were found (the @samp{-v} option inverts the sense of the exit status).
555 Exit status is 2 if there were syntax errors in the pattern,
556 inaccessible input files, or other system errors.
559 @chapter @command{grep} programs
561 @command{grep} searches the named input files (or standard input if no
562 files are named, or the file name @file{-} is given) for lines containing
563 a match to the given pattern. By default, @command{grep} prints the
564 matching lines. There are three major variants of @command{grep},
565 controlled by the following options.
570 @itemx --basic-regexp
572 @opindex --basic-regexp
573 @cindex matching basic regular expressions
574 Interpret pattern as a basic regular expression. This is the default.
577 @itemx --extended-regexp
579 @opindex --extended-regexp
580 @cindex matching extended regular expressions
581 Interpret pattern as an extended regular expression.
585 @itemx --fixed-strings
587 @opindex --fixed-strings
588 @cindex matching fixed strings
589 Interpret pattern as a list of fixed strings, separated
590 by newlines, any of which is to be matched.
594 In addition, two variant programs @sc{egrep} and @sc{fgrep} are available.
595 @sc{egrep} is the same as @samp{grep -E}. @sc{fgrep} is the
596 same as @samp{grep -F}.
598 @node Regular Expressions
599 @chapter Regular Expressions
600 @cindex regular expressions
602 A @dfn{regular expression} is a pattern that describes a set of strings.
603 Regular expressions are constructed analogously to arithmetic expressions,
604 by using various operators to combine smaller expressions.
605 @command{grep} understands two different versions of regular expression
606 syntax: ``basic'' and ``extended''. In @sc{gnu} @command{grep}, there is no
607 difference in available functionality using either syntax.
608 In other implementations, basic regular expressions are less powerful.
609 The following description applies to extended regular expressions;
610 differences for basic regular expressions are summarized afterwards.
612 The fundamental building blocks are the regular expressions that match
613 a single character. Most characters, including all letters and digits,
614 are regular expressions that match themselves. Any metacharacter
615 with special meaning may be quoted by preceding it with a backslash.
616 A list of characters enclosed by @samp{[} and @samp{]} matches any
617 single character in that list; if the first character of the list is the
618 caret @samp{^}, then it
619 matches any character @strong{not} in the list. For example, the regular
620 expression @samp{[0123456789]} matches any single digit.
621 A range of characters may be specified by giving the first
622 and last characters, separated by a hyphen.
624 Finally, certain named classes of characters are predefined, as follows.
625 Their interpretation depends on the @code{LC_CTYPE} locale; the
626 interpretation below is that of the @sc{posix} locale, which is the default
627 if no @code{LC_CTYPE} locale is specified.
629 @cindex classes of characters
630 @cindex character classes
635 @cindex alphanumeric characters
636 Alphanumeric characters:
637 @samp{[:alpha:]} and @samp{[:digit:]}.
641 @cindex alphabetic characters
642 Alphabetic characters:
643 @samp{[:lower:]} and @samp{[:upper:]}.
647 @cindex blank characters
653 @cindex control characters
654 Control characters. In @sc{ascii}, these characters have octal codes 000
655 through 037, and 177 (@code{DEL}). In other character sets, these are
656 the equivalent characters, if any.
660 @cindex digit characters
661 @cindex numeric characters
662 Digits: @code{0 1 2 3 4 5 6 7 8 9}.
666 @cindex graphic characters
667 Graphical characters:
668 @samp{[:alnum:]} and @samp{[:punct:]}.
672 @cindex lower-case letters
674 @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}.
678 @cindex printable characters
679 Printable characters:
680 @samp{[:alnum:]}, @samp{[:punct:]}, and space.
684 @cindex punctuation characters
685 Punctuation characters:
686 @code{!@: " # $ % & ' ( ) * + , - .@: / : ; < = > ?@: @@ [ \ ] ^ _ ` @{ | @} ~}.
690 @cindex space characters
691 @cindex whitespace characters
693 tab, newline, vertical tab, form feed, carriage return, and space.
697 @cindex upper-case letters
699 @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}.
704 @cindex hexadecimal digits
706 @code{0 1 2 3 4 5 6 7 8 9 A B C D E F a b c d e f}.
709 For example, @samp{[[:alnum:]]} means @samp{[0-9A-Za-z]}, except the latter
710 depends upon the @sc{posix} locale and the @sc{ascii} character
711 encoding, whereas the former is independent of locale and character set.
712 (Note that the brackets in these class names are
713 part of the symbolic names, and must be included in addition to
714 the brackets delimiting the bracket list.) Most metacharacters lose
715 their special meaning inside lists. To include a literal @samp{]}, place it
716 first in the list. Similarly, to include a literal @samp{^}, place it anywhere
717 but first. Finally, to include a literal @samp{-}, place it last.
719 The period @samp{.} matches any single character. The symbol @samp{\w}
720 is a synonym for @samp{[[:alnum:]]} and @samp{\W} is a synonym for
723 The caret @samp{^} and the dollar sign @samp{$} are metacharacters that
724 respectively match the empty string at the beginning and end
725 of a line. The symbols @samp{\<} and @samp{\>} respectively match the
726 empty string at the beginning and end of a word. The symbol
727 @samp{\b} matches the empty string at the edge of a word, and @samp{\B}
728 matches the empty string provided it's not at the edge of a word.
730 A regular expression may be followed by one of several
731 repetition operators:
738 @cindex question mark
739 @cindex match sub-expression at most once
740 The preceding item is optional and will be matched at most once.
745 @cindex match sub-expression zero or more times
746 The preceding item will be matched zero or more times.
751 The preceding item will be matched one or more times.
755 @cindex braces, one argument
756 @cindex match sub-expression n times
757 The preceding item is matched exactly @var{n} times.
761 @cindex braces, second argument omitted
762 @cindex match sub-expression n or more times
763 The preceding item is matched n or more times.
765 @item @{@var{n},@var{m}@}
767 @cindex braces, two arguments
768 The preceding item is matched at least @var{n} times, but not more than
773 Two regular expressions may be concatenated; the resulting regular
774 expression matches any string formed by concatenating two substrings
775 that respectively match the concatenated subexpressions.
777 Two regular expressions may be joined by the infix operator @samp{|}; the
778 resulting regular expression matches any string matching either
781 Repetition takes precedence over concatenation, which in turn
782 takes precedence over alternation. A whole subexpression may be
783 enclosed in parentheses to override these precedence rules.
785 The backreference @samp{\@var{n}}, where @var{n} is a single digit, matches the
786 substring previously matched by the @var{n}th parenthesized subexpression
787 of the regular expression.
789 @cindex basic regular expressions
790 In basic regular expressions the metacharacters @samp{?}, @samp{+},
791 @samp{@{}, @samp{|}, @samp{(}, and @samp{)} lose their special meaning;
792 instead use the backslashed versions @samp{\?}, @samp{\+}, @samp{\@{},
793 @samp{\|}, @samp{\(}, and @samp{\)}.
795 @cindex interval specifications
796 Traditional @command{egrep} did not support the @samp{@{} metacharacter,
797 and some @command{egrep} implementations support @samp{\@{} instead, so
798 portable scripts should avoid @samp{@{} in @samp{egrep} patterns and
799 should use @samp{[@{]} to match a literal @samp{@{}.
801 @sc{gnu} @command{egrep} attempts to support traditional usage by
802 assuming that @samp{@{} is not special if it would be the start of an
803 invalid interval specification. For example, the shell command
804 @samp{egrep '@{1'} searches for the two-character string @samp{@{1}
805 instead of reporting a syntax error in the regular expression.
806 @sc{posix.2} allows this behavior as an extension, but portable scripts
812 @cindex Usage, examples
813 Here is an example shell command that invokes @sc{gnu} @command{grep}:
816 grep -i 'hello.*world' menu.h main.c
820 This lists all lines in the files @file{menu.h} and @file{main.c} that
821 contain the string @samp{hello} followed by the string @samp{world};
822 this is because @samp{.*} matches zero or more characters within a line.
823 @xref{Regular Expressions}. The @samp{-i} option causes @command{grep}
824 to ignore case, causing it to match the line @samp{Hello, world!}, which
825 it would not otherwise match. @xref{Invoking}, for more details about
826 how to invoke @command{grep}.
828 @cindex Using @command{grep}, Q&A
829 @cindex FAQ about @command{grep} usage
830 Here are some common questions and answers about @command{grep} usage.
835 How can I list just the names of matching files?
842 lists the names of all C files in the current directory whose contents
846 How do I search directories recursively?
849 grep -r 'hello' /home/gigi
853 searches for @samp{hello} in all files under the directory
854 @file{/home/gigi}. For more control of which files are searched, use
855 @command{find}, @command{grep} and @command{xargs}. For example,
856 the following command searches only C files:
859 find /home/gigi -name '*.c' -print | xargs grep 'hello' /dev/null
863 What if a pattern has a leading @samp{-}?
866 grep -e '--cut here--' *
870 searches for all lines matching @samp{--cut here--}. Without @samp{-e},
871 @command{grep} would attempt to parse @samp{--cut here--} as a list of
875 Suppose I want to search for a whole word, not a part of a word?
882 searches only for instances of @samp{hello} that are entire words; it
883 does not match @samp{Othello}. For more control, use @samp{\<} and
884 @samp{\>} to match the start and end of words. For example:
891 searches only for words ending in @samp{hello}, so it matches the word
895 How do I output context around the matching lines?
902 prints two lines of context around each matching line.
905 How do I force grep to print the name of the file?
907 Append @file{/dev/null}:
910 grep 'eli' /etc/passwd /dev/null
914 Why do people use strange regular expressions on @command{ps} output?
917 ps -ef | grep '[c]ron'
920 If the pattern had been written without the square brackets, it would
921 have matched not only the @command{ps} output line for @command{cron},
922 but also the @command{ps} output line for @command{grep}.
925 Why does @command{grep} report ``Binary file matches''?
927 If @command{grep} listed all matching ``lines'' from a binary file, it
928 would probably generate output that is not useful, and it might even
929 muck up your display. So @sc{gnu} @command{grep} suppresses output from
930 files that appear to be binary files. To force @sc{gnu} @command{grep}
931 to output lines even from files that appear to be binary, use the
932 @samp{-a} or @samp{--binary-files=text} option. To eliminate the
933 ``Binary file matches'' messages, use the @samp{-I} or
934 @samp{--binary-files=without-match} option.
937 Why doesn't @samp{grep -lv} print nonmatching file names?
939 @samp{grep -lv} lists the names of all files containing one or more
940 lines that do not match. To list the names of all files that contain no
941 matching lines, use the @samp{-L} or @samp{--files-without-match}
945 I can do @sc{or} with @samp{|}, but what about @sc{and}?
948 grep 'paul' /etc/motd | grep 'franc,ois'
952 finds all lines that contain both @samp{paul} and @samp{franc,ois}.
955 How can I search in both standard input and in files?
957 Use the special file name @samp{-}:
960 cat /etc/passwd | grep 'alain' - /etc/motd
965 @chapter Reporting bugs
967 @cindex Bugs, reporting
968 Email bug reports to @email{bug-gnu-utils@@gnu.org}.
969 Be sure to include the word ``grep'' somewhere in the ``Subject:'' field.
971 Large repetition counts in the @samp{@{m,n@}} construct may cause
972 @command{grep} to use lots of memory. In addition, certain other
973 obscure regular expressions require exponential time and
974 space, and may cause grep to run out of memory.
975 Backreferences are very slow, and may require exponential time.
979 @unnumbered Concept Index
981 This is a general index of all issues discussed in this manual, with the
982 exception of the @command{grep} commands and command-line options.
990 This is an alphabetical list of all @command{grep} commands, command-line
991 options, and environment variables.