1GREP(1) User Commands GREP(1)
2
3
4
6 grep, egrep, fgrep - print lines that match patterns
7
9 grep [OPTION...] PATTERNS [FILE...]
10 grep [OPTION...] -e PATTERNS ... [FILE...]
11 grep [OPTION...] -f PATTERN_FILE ... [FILE...]
12
14 grep searches for PATTERNS in each FILE. PATTERNS is one or more
15 patterns separated by newline characters, and grep prints each line
16 that matches a pattern. Typically PATTERNS should be quoted when grep
17 is used in a shell command.
18
19 A FILE of “-” stands for standard input. If no FILE is given,
20 recursive searches examine the working directory, and nonrecursive
21 searches read standard input.
22
23 In addition, the variant programs egrep and fgrep are the same as
24 grep -E and grep -F, respectively. These variants are deprecated, but
25 are provided for backward compatibility.
26
28 Generic Program Information
29 --help Output a usage message and exit.
30
31 -V, --version
32 Output the version number of grep and exit.
33
34 Pattern Syntax
35 -E, --extended-regexp
36 Interpret PATTERNS as extended regular expressions (EREs, see
37 below).
38
39 -F, --fixed-strings
40 Interpret PATTERNS as fixed strings, not regular expressions.
41
42 -G, --basic-regexp
43 Interpret PATTERNS as basic regular expressions (BREs, see
44 below). This is the default.
45
46 -P, --perl-regexp
47 Interpret PATTERNS as Perl-compatible regular expressions
48 (PCREs). This option is experimental when combined with the -z
49 (--null-data) option, and grep -P may warn of unimplemented
50 features.
51
52 Matching Control
53 -e PATTERNS, --regexp=PATTERNS
54 Use PATTERNS as the patterns. If this option is used multiple
55 times or is combined with the -f (--file) option, search for all
56 patterns given. This option can be used to protect a pattern
57 beginning with “-”.
58
59 -f FILE, --file=FILE
60 Obtain patterns from FILE, one per line. If this option is used
61 multiple times or is combined with the -e (--regexp) option,
62 search for all patterns given. The empty file contains zero
63 patterns, and therefore matches nothing.
64
65 -i, --ignore-case
66 Ignore case distinctions in patterns and input data, so that
67 characters that differ only in case match each other.
68
69 --no-ignore-case
70 Do not ignore case distinctions in patterns and input data.
71 This is the default. This option is useful for passing to shell
72 scripts that already use -i, to cancel its effects because the
73 two options override each other.
74
75 -v, --invert-match
76 Invert the sense of matching, to select non-matching lines.
77
78 -w, --word-regexp
79 Select only those lines containing matches that form whole
80 words. The test is that the matching substring must either be
81 at the beginning of the line, or preceded by a non-word
82 constituent character. Similarly, it must be either at the end
83 of the line or followed by a non-word constituent character.
84 Word-constituent characters are letters, digits, and the
85 underscore. This option has no effect if -x is also specified.
86
87 -x, --line-regexp
88 Select only those matches that exactly match the whole line.
89 For a regular expression pattern, this is like parenthesizing
90 the pattern and then surrounding it with ^ and $.
91
92 -y Obsolete synonym for -i.
93
94 General Output Control
95 -c, --count
96 Suppress normal output; instead print a count of matching lines
97 for each input file. With the -v, --invert-match option (see
98 below), count non-matching lines.
99
100 --color[=WHEN], --colour[=WHEN]
101 Surround the matched (non-empty) strings, matching lines,
102 context lines, file names, line numbers, byte offsets, and
103 separators (for fields and groups of context lines) with escape
104 sequences to display them in color on the terminal. The colors
105 are defined by the environment variable GREP_COLORS. The
106 deprecated environment variable GREP_COLOR is still supported,
107 but its setting does not have priority. WHEN is never, always,
108 or auto.
109
110 -L, --files-without-match
111 Suppress normal output; instead print the name of each input
112 file from which no output would normally have been printed. The
113 scanning will stop on the first match.
114
115 -l, --files-with-matches
116 Suppress normal output; instead print the name of each input
117 file from which output would normally have been printed. The
118 scanning will stop on the first match.
119
120 -m NUM, --max-count=NUM
121 Stop reading a file after NUM matching lines. If the input is
122 standard input from a regular file, and NUM matching lines are
123 output, grep ensures that the standard input is positioned to
124 just after the last matching line before exiting, regardless of
125 the presence of trailing context lines. This enables a calling
126 process to resume a search. When grep stops after NUM matching
127 lines, it outputs any trailing context lines. When the -c or
128 --count option is also used, grep does not output a count
129 greater than NUM. When the -v or --invert-match option is also
130 used, grep stops after outputting NUM non-matching lines.
131
132 -o, --only-matching
133 Print only the matched (non-empty) parts of a matching line,
134 with each such part on a separate output line.
135
136 -q, --quiet, --silent
137 Quiet; do not write anything to standard output. Exit
138 immediately with zero status if any match is found, even if an
139 error was detected. Also see the -s or --no-messages option.
140
141 -s, --no-messages
142 Suppress error messages about nonexistent or unreadable files.
143
144 Output Line Prefix Control
145 -b, --byte-offset
146 Print the 0-based byte offset within the input file before each
147 line of output. If -o (--only-matching) is specified, print the
148 offset of the matching part itself.
149
150 -H, --with-filename
151 Print the file name for each match. This is the default when
152 there is more than one file to search.
153
154 -h, --no-filename
155 Suppress the prefixing of file names on output. This is the
156 default when there is only one file (or only standard input) to
157 search.
158
159 --label=LABEL
160 Display input actually coming from standard input as input
161 coming from file LABEL. This can be useful for commands that
162 transform a file's contents before searching, e.g., gzip -cd
163 foo.gz | grep --label=foo -H 'some pattern'. See also the -H
164 option.
165
166 -n, --line-number
167 Prefix each line of output with the 1-based line number within
168 its input file.
169
170 -T, --initial-tab
171 Make sure that the first character of actual line content lies
172 on a tab stop, so that the alignment of tabs looks normal. This
173 is useful with options that prefix their output to the actual
174 content: -H,-n, and -b. In order to improve the probability
175 that lines from a single file will all start at the same column,
176 this also causes the line number and byte offset (if present) to
177 be printed in a minimum size field width.
178
179 -u, --unix-byte-offsets
180 Report Unix-style byte offsets. This switch causes grep to
181 report byte offsets as if the file were a Unix-style text file,
182 i.e., with CR characters stripped off. This will produce
183 results identical to running grep on a Unix machine. This
184 option has no effect unless -b option is also used; it has no
185 effect on platforms other than MS-DOS and MS-Windows.
186
187 -Z, --null
188 Output a zero byte (the ASCII NUL character) instead of the
189 character that normally follows a file name. For example, grep
190 -lZ outputs a zero byte after each file name instead of the
191 usual newline. This option makes the output unambiguous, even
192 in the presence of file names containing unusual characters like
193 newlines. This option can be used with commands like find
194 -print0, perl -0, sort -z, and xargs -0 to process arbitrary
195 file names, even those that contain newline characters.
196
197 Context Line Control
198 -A NUM, --after-context=NUM
199 Print NUM lines of trailing context after matching lines.
200 Places a line containing a group separator (described under
201 --group-separator) between contiguous groups of matches. With
202 the -o or --only-matching option, this has no effect and a
203 warning is given.
204
205 -B NUM, --before-context=NUM
206 Print NUM lines of leading context before matching lines.
207 Places a line containing a group separator (described under
208 --group-separator) between contiguous groups of matches. With
209 the -o or --only-matching option, this has no effect and a
210 warning is given.
211
212 -C NUM, -NUM, --context=NUM
213 Print NUM lines of output context. Places a line containing a
214 group separator (described under --group-separator) between
215 contiguous groups of matches. With the -o or --only-matching
216 option, this has no effect and a warning is given.
217
218 --group-separator=SEP
219 Use SEP as a group separator. By default SEP is double hyphen
220 (--).
221
222 --no-group-separator
223 Use empty string as a group separator.
224
225 File and Directory Selection
226 -a, --text
227 Process a binary file as if it were text; this is equivalent to
228 the --binary-files=text option.
229
230 --binary-files=TYPE
231 If a file's data or metadata indicate that the file contains
232 binary data, assume that the file is of type TYPE. Non-text
233 bytes indicate binary data; these are either output bytes that
234 are improperly encoded for the current locale, or null input
235 bytes when the -z option is not given.
236
237 By default, TYPE is binary, and grep suppresses output after
238 null input binary data is discovered, and suppresses output
239 lines that contain improperly encoded data. When some output is
240 suppressed, grep follows any output with a one-line message
241 saying that a binary file matches.
242
243 If TYPE is without-match, when grep discovers null input binary
244 data it assumes that the rest of the file does not match; this
245 is equivalent to the -I option.
246
247 If TYPE is text, grep processes a binary file as if it were
248 text; this is equivalent to the -a option.
249
250 When type is binary, grep may treat non-text bytes as line
251 terminators even without the -z option. This means choosing
252 binary versus text can affect whether a pattern matches a file.
253 For example, when type is binary the pattern q$ might match q
254 immediately followed by a null byte, even though this is not
255 matched when type is text. Conversely, when type is binary the
256 pattern . (period) might not match a null byte.
257
258 Warning: The -a option might output binary garbage, which can
259 have nasty side effects if the output is a terminal and if the
260 terminal driver interprets some of it as commands. On the other
261 hand, when reading files whose text encodings are unknown, it
262 can be helpful to use -a or to set LC_ALL='C' in the
263 environment, in order to find more matches even if the matches
264 are unsafe for direct display.
265
266 -D ACTION, --devices=ACTION
267 If an input file is a device, FIFO or socket, use ACTION to
268 process it. By default, ACTION is read, which means that
269 devices are read just as if they were ordinary files. If ACTION
270 is skip, devices are silently skipped.
271
272 -d ACTION, --directories=ACTION
273 If an input file is a directory, use ACTION to process it. By
274 default, ACTION is read, i.e., read directories just as if they
275 were ordinary files. If ACTION is skip, silently skip
276 directories. If ACTION is recurse, read all files under each
277 directory, recursively, following symbolic links only if they
278 are on the command line. This is equivalent to the -r option.
279
280 --exclude=GLOB
281 Skip any command-line file with a name suffix that matches the
282 pattern GLOB, using wildcard matching; a name suffix is either
283 the whole name, or a trailing part that starts with a non-slash
284 character immediately after a slash (/) in the name. When
285 searching recursively, skip any subfile whose base name matches
286 GLOB; the base name is the part after the last slash. A pattern
287 can use *, ?, and [...] as wildcards, and \ to quote a wildcard
288 or backslash character literally.
289
290 --exclude-from=FILE
291 Skip files whose base name matches any of the file-name globs
292 read from FILE (using wildcard matching as described under
293 --exclude).
294
295 --exclude-dir=GLOB
296 Skip any command-line directory with a name suffix that matches
297 the pattern GLOB. When searching recursively, skip any
298 subdirectory whose base name matches GLOB. Ignore any redundant
299 trailing slashes in GLOB.
300
301 -I Process a binary file as if it did not contain matching data;
302 this is equivalent to the --binary-files=without-match option.
303
304 --include=GLOB
305 Search only files whose base name matches GLOB (using wildcard
306 matching as described under --exclude).
307
308 -r, --recursive
309 Read all files under each directory, recursively, following
310 symbolic links only if they are on the command line. Note that
311 if no file operand is given, grep searches the working
312 directory. This is equivalent to the -d recurse option.
313
314 -R, --dereference-recursive
315 Read all files under each directory, recursively. Follow all
316 symbolic links, unlike -r.
317
318 Other Options
319 --line-buffered
320 Use line buffering on output. This can cause a performance
321 penalty.
322
323 -U, --binary
324 Treat the file(s) as binary. By default, under MS-DOS and MS-
325 Windows, grep guesses whether a file is text or binary as
326 described for the --binary-files option. If grep decides the
327 file is a text file, it strips the CR characters from the
328 original file contents (to make regular expressions with ^ and $
329 work correctly). Specifying -U overrules this guesswork,
330 causing all files to be read and passed to the matching
331 mechanism verbatim; if the file is a text file with CR/LF pairs
332 at the end of each line, this will cause some regular
333 expressions to fail. This option has no effect on platforms
334 other than MS-DOS and MS-Windows.
335
336 -z, --null-data
337 Treat input and output data as sequences of lines, each
338 terminated by a zero byte (the ASCII NUL character) instead of a
339 newline. Like the -Z or --null option, this option can be used
340 with commands like sort -z to process arbitrary file names.
341
343 A regular expression is a pattern that describes a set of strings.
344 Regular expressions are constructed analogously to arithmetic
345 expressions, by using various operators to combine smaller expressions.
346
347 grep understands three different versions of regular expression syntax:
348 “basic” (BRE), “extended” (ERE) and “perl” (PCRE). In GNU grep there
349 is no difference in available functionality between basic and extended
350 syntaxes. In other implementations, basic regular expressions are less
351 powerful. The following description applies to extended regular
352 expressions; differences for basic regular expressions are summarized
353 afterwards. Perl-compatible regular expressions give additional
354 functionality, and are documented in pcresyntax(3) and pcrepattern(3),
355 but work only if PCRE is available in the system.
356
357 The fundamental building blocks are the regular expressions that match
358 a single character. Most characters, including all letters and digits,
359 are regular expressions that match themselves. Any meta-character with
360 special meaning may be quoted by preceding it with a backslash.
361
362 The period . matches any single character. It is unspecified whether
363 it matches an encoding error.
364
365 Character Classes and Bracket Expressions
366 A bracket expression is a list of characters enclosed by [ and ]. It
367 matches any single character in that list. If the first character of
368 the list is the caret ^ then it matches any character not in the list;
369 it is unspecified whether it matches an encoding error. For example,
370 the regular expression [0123456789] matches any single digit.
371
372 Within a bracket expression, a range expression consists of two
373 characters separated by a hyphen. It matches any single character that
374 sorts between the two characters, inclusive, using the locale's
375 collating sequence and character set. For example, in the default C
376 locale, [a-d] is equivalent to [abcd]. Many locales sort characters in
377 dictionary order, and in these locales [a-d] is typically not
378 equivalent to [abcd]; it might be equivalent to [aBbCcDd], for example.
379 To obtain the traditional interpretation of bracket expressions, you
380 can use the C locale by setting the LC_ALL environment variable to the
381 value C.
382
383 Finally, certain named classes of characters are predefined within
384 bracket expressions, as follows. Their names are self explanatory, and
385 they are [:alnum:], [:alpha:], [:blank:], [:cntrl:], [:digit:],
386 [:graph:], [:lower:], [:print:], [:punct:], [:space:], [:upper:], and
387 [:xdigit:]. For example, [[:alnum:]] means the character class of
388 numbers and letters in the current locale. In the C locale and ASCII
389 character set encoding, this is the same as [0-9A-Za-z]. (Note that
390 the brackets in these class names are part of the symbolic names, and
391 must be included in addition to the brackets delimiting the bracket
392 expression.) Most meta-characters lose their special meaning inside
393 bracket expressions. To include a literal ] place it first in the
394 list. Similarly, to include a literal ^ place it anywhere but first.
395 Finally, to include a literal - place it last.
396
397 Anchoring
398 The caret ^ and the dollar sign $ are meta-characters that respectively
399 match the empty string at the beginning and end of a line.
400
401 The Backslash Character and Special Expressions
402 The symbols \< and \> respectively match the empty string at the
403 beginning and end of a word. The symbol \b matches the empty string at
404 the edge of a word, and \B matches the empty string provided it's not
405 at the edge of a word. The symbol \w is a synonym for [_[:alnum:]] and
406 \W is a synonym for [^_[:alnum:]].
407
408 Repetition
409 A regular expression may be followed by one of several repetition
410 operators:
411 ? The preceding item is optional and matched at most once.
412 * The preceding item will be matched zero or more times.
413 + The preceding item will be matched one or more times.
414 {n} The preceding item is matched exactly n times.
415 {n,} The preceding item is matched n or more times.
416 {,m} The preceding item is matched at most m times. This is a GNU
417 extension.
418 {n,m} The preceding item is matched at least n times, but not more
419 than m times.
420
421 Concatenation
422 Two regular expressions may be concatenated; the resulting regular
423 expression matches any string formed by concatenating two substrings
424 that respectively match the concatenated expressions.
425
426 Alternation
427 Two regular expressions may be joined by the infix operator |; the
428 resulting regular expression matches any string matching either
429 alternate expression.
430
431 Precedence
432 Repetition takes precedence over concatenation, which in turn takes
433 precedence over alternation. A whole expression may be enclosed in
434 parentheses to override these precedence rules and form a
435 subexpression.
436
437 Back-references and Subexpressions
438 The back-reference \n, where n is a single digit, matches the substring
439 previously matched by the nth parenthesized subexpression of the
440 regular expression.
441
442 Basic vs Extended Regular Expressions
443 In basic regular expressions the meta-characters ?, +, {, |, (, and )
444 lose their special meaning; instead use the backslashed versions \?,
445 \+, \{, \|, \(, and \).
446
448 Normally the exit status is 0 if a line is selected, 1 if no lines were
449 selected, and 2 if an error occurred. However, if the -q or --quiet or
450 --silent is used and a line is selected, the exit status is 0 even if
451 an error occurred.
452
454 The behavior of grep is affected by the following environment
455 variables.
456
457 The locale for category LC_foo is specified by examining the three
458 environment variables LC_ALL, LC_foo, LANG, in that order. The first
459 of these variables that is set specifies the locale. For example, if
460 LC_ALL is not set, but LC_MESSAGES is set to pt_BR, then the Brazilian
461 Portuguese locale is used for the LC_MESSAGES category. The C locale
462 is used if none of these environment variables are set, if the locale
463 catalog is not installed, or if grep was not compiled with national
464 language support (NLS). The shell command locale -a lists locales that
465 are currently available.
466
467 GREP_OPTIONS
468 This variable specifies default options to be placed in front of
469 any explicit options. As this causes problems when writing
470 portable scripts, this feature will be removed in a future
471 release of grep, and grep warns if it is used. Please use an
472 alias or script instead.
473
474 GREP_COLOR
475 This variable specifies the color used to highlight matched
476 (non-empty) text. It is deprecated in favor of GREP_COLORS, but
477 still supported. The mt, ms, and mc capabilities of GREP_COLORS
478 have priority over it. It can only specify the color used to
479 highlight the matching non-empty text in any matching line (a
480 selected line when the -v command-line option is omitted, or a
481 context line when -v is specified). The default is 01;31, which
482 means a bold red foreground text on the terminal's default
483 background.
484
485 GREP_COLORS
486 Specifies the colors and other attributes used to highlight
487 various parts of the output. Its value is a colon-separated
488 list of capabilities that defaults to
489 ms=01;31:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36 with the rv
490 and ne boolean capabilities omitted (i.e., false). Supported
491 capabilities are as follows.
492
493 sl= SGR substring for whole selected lines (i.e., matching
494 lines when the -v command-line option is omitted, or non-
495 matching lines when -v is specified). If however the
496 boolean rv capability and the -v command-line option are
497 both specified, it applies to context matching lines
498 instead. The default is empty (i.e., the terminal's
499 default color pair).
500
501 cx= SGR substring for whole context lines (i.e., non-matching
502 lines when the -v command-line option is omitted, or
503 matching lines when -v is specified). If however the
504 boolean rv capability and the -v command-line option are
505 both specified, it applies to selected non-matching lines
506 instead. The default is empty (i.e., the terminal's
507 default color pair).
508
509 rv Boolean value that reverses (swaps) the meanings of the
510 sl= and cx= capabilities when the -v command-line option
511 is specified. The default is false (i.e., the capability
512 is omitted).
513
514 mt=01;31
515 SGR substring for matching non-empty text in any matching
516 line (i.e., a selected line when the -v command-line
517 option is omitted, or a context line when -v is
518 specified). Setting this is equivalent to setting both
519 ms= and mc= at once to the same value. The default is a
520 bold red text foreground over the current line
521 background.
522
523 ms=01;31
524 SGR substring for matching non-empty text in a selected
525 line. (This is only used when the -v command-line option
526 is omitted.) The effect of the sl= (or cx= if rv)
527 capability remains active when this kicks in. The
528 default is a bold red text foreground over the current
529 line background.
530
531 mc=01;31
532 SGR substring for matching non-empty text in a context
533 line. (This is only used when the -v command-line option
534 is specified.) The effect of the cx= (or sl= if rv)
535 capability remains active when this kicks in. The
536 default is a bold red text foreground over the current
537 line background.
538
539 fn=35 SGR substring for file names prefixing any content line.
540 The default is a magenta text foreground over the
541 terminal's default background.
542
543 ln=32 SGR substring for line numbers prefixing any content
544 line. The default is a green text foreground over the
545 terminal's default background.
546
547 bn=32 SGR substring for byte offsets prefixing any content
548 line. The default is a green text foreground over the
549 terminal's default background.
550
551 se=36 SGR substring for separators that are inserted between
552 selected line fields (:), between context line fields,
553 (-), and between groups of adjacent lines when nonzero
554 context is specified (--). The default is a cyan text
555 foreground over the terminal's default background.
556
557 ne Boolean value that prevents clearing to the end of line
558 using Erase in Line (EL) to Right (\33[K) each time a
559 colorized item ends. This is needed on terminals on
560 which EL is not supported. It is otherwise useful on
561 terminals for which the back_color_erase (bce) boolean
562 terminfo capability does not apply, when the chosen
563 highlight colors do not affect the background, or when EL
564 is too slow or causes too much flicker. The default is
565 false (i.e., the capability is omitted).
566
567 Note that boolean capabilities have no =... part. They are
568 omitted (i.e., false) by default and become true when specified.
569
570 See the Select Graphic Rendition (SGR) section in the
571 documentation of the text terminal that is used for permitted
572 values and their meaning as character attributes. These
573 substring values are integers in decimal representation and can
574 be concatenated with semicolons. grep takes care of assembling
575 the result into a complete SGR sequence (\33[...m). Common
576 values to concatenate include 1 for bold, 4 for underline, 5 for
577 blink, 7 for inverse, 39 for default foreground color, 30 to 37
578 for foreground colors, 90 to 97 for 16-color mode foreground
579 colors, 38;5;0 to 38;5;255 for 88-color and 256-color modes
580 foreground colors, 49 for default background color, 40 to 47 for
581 background colors, 100 to 107 for 16-color mode background
582 colors, and 48;5;0 to 48;5;255 for 88-color and 256-color modes
583 background colors.
584
585 LC_ALL, LC_COLLATE, LANG
586 These variables specify the locale for the LC_COLLATE category,
587 which determines the collating sequence used to interpret range
588 expressions like [a-z].
589
590 LC_ALL, LC_CTYPE, LANG
591 These variables specify the locale for the LC_CTYPE category,
592 which determines the type of characters, e.g., which characters
593 are whitespace. This category also determines the character
594 encoding, that is, whether text is encoded in UTF-8, ASCII, or
595 some other encoding. In the C or POSIX locale, all characters
596 are encoded as a single byte and every byte is a valid
597 character.
598
599 LC_ALL, LC_MESSAGES, LANG
600 These variables specify the locale for the LC_MESSAGES category,
601 which determines the language that grep uses for messages. The
602 default C locale uses American English messages.
603
604 POSIXLY_CORRECT
605 If set, grep behaves as POSIX requires; otherwise, grep behaves
606 more like other GNU programs. POSIX requires that options that
607 follow file names must be treated as file names; by default,
608 such options are permuted to the front of the operand list and
609 are treated as options. Also, POSIX requires that unrecognized
610 options be diagnosed as “illegal”, but since they are not really
611 against the law the default is to diagnose them as “invalid”.
612 POSIXLY_CORRECT also disables _N_GNU_nonoption_argv_flags_,
613 described below.
614
615 _N_GNU_nonoption_argv_flags_
616 (Here N is grep's numeric process ID.) If the ith character of
617 this environment variable's value is 1, do not consider the ith
618 operand of grep to be an option, even if it appears to be one.
619 A shell can put this variable in the environment for each
620 command it runs, specifying which operands are the results of
621 file name wildcard expansion and therefore should not be treated
622 as options. This behavior is available only with the GNU C
623 library, and only when POSIXLY_CORRECT is not set.
624
626 This man page is maintained only fitfully; the full documentation is
627 often more up-to-date.
628
630 Copyright 1998-2000, 2002, 2005-2020 Free Software Foundation, Inc.
631
632 This is free software; see the source for copying conditions. There is
633 NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
634 PURPOSE.
635
637 Reporting Bugs
638 Email bug reports to the bug-reporting address ⟨bug-grep@gnu.org⟩. An
639 email archive ⟨https://lists.gnu.org/mailman/listinfo/bug-grep⟩ and a
640 bug tracker ⟨https://debbugs.gnu.org/cgi/pkgreport.cgi?package=grep⟩
641 are available.
642
643 Known Bugs
644 Large repetition counts in the {n,m} construct may cause grep to use
645 lots of memory. In addition, certain other obscure regular expressions
646 require exponential time and space, and may cause grep to run out of
647 memory.
648
649 Back-references are very slow, and may require exponential time.
650
652 The following example outputs the location and contents of any line
653 containing “f” and ending in “.c”, within all files in the current
654 directory whose names contain “g” and end in “.h”. The -n option out‐
655 puts line numbers, the -- argument treats expansions of “*g*.h” start‐
656 ing with “-” as file names not options, and the empty file /dev/null
657 causes file names to be output even if only one file name happens to be
658 of the form “*g*.h”.
659
660 $ grep -n -- 'f.*\.c$' *g*.h /dev/null
661 argmatch.h:1:/* definitions and prototypes for argmatch.c
662
663 The only line that matches is line 1 of argmatch.h. Note that the reg‐
664 ular expression syntax used in the pattern differs from the globbing
665 syntax that the shell uses to match file names.
666
668 Regular Manual Pages
669 awk(1), cmp(1), diff(1), find(1), perl(1), sed(1), sort(1), xargs(1),
670 read(2), pcre(3), pcresyntax(3), pcrepattern(3), terminfo(5), glob(7),
671 regex(7).
672
673 Full Documentation
674 A complete manual ⟨https://www.gnu.org/software/grep/manual/⟩ is avail‐
675 able. If the info and grep programs are properly installed at your
676 site, the command
677
678 info grep
679
680 should give you access to the complete manual.
681
682
683
684GNU grep 3.4 2019-12-29 GREP(1)