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