Lines Matching +full:file +full:- +full:lines
3 pcre2grep - a grep with Perl-compatible regular expressions.
16 for a quick-reference summary of pattern syntax, or
23 Patterns, whether supplied on the command line or in a separate file, are given
35 pattern to be matched when neither \fB-e\fP nor \fB-f\fP is present.
37 arguments are treated as path names. At least one of \fB-e\fP, \fB-f\fP, or an
44 pcre2grep some-pattern file1 - file3
47 pattern is copied to the standard output, and if there is more than one file,
48 the file name is output at the start of each line, followed by a colon.
50 particular, the \fB-M\fP option makes it possible to search for strings that
52 \fB-N\fP (\fB--newline\fP) option.
55 controlled by parameters that can be set by the \fB--buffer-size\fP and
56 \fB--max-buffer-size\fP options. The first of these sets the size of buffer
57 that is obtained at the start of processing. If an input file contains very
58 long lines, a larger buffer may be needed; this is handled by automatically
59 extending the buffer, up to the limit specified by \fB--max-buffer-size\fP. The
66 allow for buffering "before" and "after" lines. If the buffer size is too
67 small, fewer than requested "before" and "after" lines may be output.
71 (specified by the use of \fB-e\fP and/or \fB-f\fP), each pattern is applied to
72 each line in the order in which they are defined, except that all the \fB-e\fP
73 patterns are tried before the \fB-f\fP patterns.
76 considered. However, if \fB--colour\fP (or \fB--color\fP) is used to colour the
77 matching substrings, or if \fB--only-matching\fP, \fB--file-offsets\fP, or
78 \fB--line-offsets\fP is used to output only the part of the line that matched
98 The \fB--locale\fP option can be used to override this.
107 has support for one or both of these file types by running it with the
108 \fB--help\fP option. If the appropriate support is not present, all files are
110 from a compressed .gz or .bz2 file, the \fB--line-buffered\fP option is
117 By default, a file that contains a binary zero byte within the first 1024 bytes
118 is identified as a binary file, and is processed specially. However, if the
120 zero, the test for a binary file is not applied. See the \fB--binary-files\fP
129 from a file via the \fB-f\fP option may contain binary zeros.
136 example, both the \fB-H\fP and \fB-l\fP options affect the printing of file
142 \fB--\fP
145 processing of patterns and file names that start with hyphens.
147 \fB-A\fP \fInumber\fP, \fB--after-context=\fP\fInumber\fP
148 Output up to \fInumber\fP lines of context after each matching line. Fewer
149 lines are output if the next match or the end of the file is reached, or if the
150 processing buffer size has been set too small. If file names and/or line
152 context lines. A line containing "--" is output between each group of lines,
153 unless they are in fact contiguous in the input file. The value of \fInumber\fP
154 is expected to be relatively small. When \fB-c\fP is used, \fB-A\fP is ignored.
156 \fB-a\fP, \fB--text\fP
158 \fB--binary-files\fP=\fItext\fP.
160 \fB-B\fP \fInumber\fP, \fB--before-context=\fP\fInumber\fP
161 Output up to \fInumber\fP lines of context before each matching line. Fewer
162 lines are output if the previous match or the start of the file is within
163 \fInumber\fP lines, or if the processing buffer size has been set too small. If
164 file names and/or line numbers are being output, a hyphen separator is used
165 instead of a colon for the context lines. A line containing "--" is output
166 between each group of lines, unless they are in fact contiguous in the input
167 file. The value of \fInumber\fP is expected to be relatively small. When
168 \fB-c\fP is used, \fB-B\fP is ignored.
170 \fB--binary-files=\fP\fIword\fP
173 "Binary file <name> matches" when a match succeeds. If the word is "text",
174 which is equivalent to the \fB-a\fP or \fB--text\fP option, binary files are
175 processed in the same way as any other file. In this case, when a match
177 sent to a terminal. If the word is "without-match", which is equivalent to the
178 \fB-I\fP option, binary files are not processed at all; they are assumed not to
182 \fB--buffer-size=\fP\fInumber\fP
185 \fB--max-buffer-size\fP below.
187 \fB-C\fP \fInumber\fP, \fB--context=\fP\fInumber\fP
188 Output \fInumber\fP lines of context both before and after each matching line.
189 This is equivalent to setting both \fB-A\fP and \fB-B\fP to the same value.
191 \fB-c\fP, \fB--count\fP
192 Do not output lines from the files that are being scanned; instead output the
193 number of lines that would have been shown, either because they matched, or, if
194 \fB-v\fP is set, because they failed to match. By default, this count is
195 exactly the same as the number of lines that would have been output, but if the
196 \fB-M\fP (multiline) option is used (without \fB-v\fP), there may be more
197 suppressed lines than the count (that is, the number of matches).
199 If no lines are selected, the number zero is output. If several files are are
200 being scanned, a count is output for each of them and the \fB-t\fP option can
202 \fB--files-with-matches\fP option is also used, only those files whose counts
203 are greater than zero are listed. When \fB-c\fP is used, the \fB-A\fP,
204 \fB-B\fP, and \fB-C\fP options are ignored.
206 \fB--colour\fP, \fB--color\fP
207 If this option is given without any data, it is equivalent to "--colour=auto".
211 \fB--colour=\fP\fIvalue\fP, \fB--color=\fP\fIvalue\fP
226 followed by two semicolon-separated colours, terminated by the end of the
237 \fB-D\fP \fIaction\fP, \fB--devices=\fP\fIaction\fP
238 If an input path is not a regular file or a directory, "action" specifies how
242 \fB-d\fP \fIaction\fP, \fB--directories=\fP\fIaction\fP
244 Valid values are "read" (the default in non-Windows environments, for
245 compatibility with GNU grep), "recurse" (equivalent to the \fB-r\fP option), or
249 end-of-file; in others it may provoke an error.
251 \fB--depth-limit\fP=\fInumber\fP
252 See \fB--match-limit\fP below.
254 \fB-e\fP \fIpattern\fP, \fB--regex=\fP\fIpattern\fP, \fB--regexp=\fP\fIpattern\fP
257 single pattern that starts with a hyphen. When \fB-e\fP is used, no argument
258 pattern is taken from the command line; all arguments are treated as file
262 If \fB-f\fP is used with \fB-e\fP, the command line patterns are matched first,
263 followed by the patterns from the file(s), independent of the order in which
264 these options are specified. Note that multiple use of \fB-e\fP is not the same
269 matters only if you are using \fB-o\fP or \fB--colo(u)r\fP to show the part(s)
272 \fB--exclude\fP=\fIpattern\fP
275 obtained from \fB--file-list\fP, or by scanning a directory. The pattern is a
277 file name, not the entire path. The \fB-F\fP, \fB-w\fP, and \fB-x\fP options do
279 to specify multiple patterns. If a file name matches both an \fB--include\fP
280 and an \fB--exclude\fP pattern, it is excluded. There is no short form for this
283 \fB--exclude-from=\fP\fIfilename\fP
284 Treat each non-empty line of the file as the data for an \fB--exclude\fP
285 option. What constitutes a newline when reading the file is the operating
286 system's default. The \fB--newline\fP option has no effect on this option. This
290 \fB--exclude-dir\fP=\fIpattern\fP
292 whatever the setting of the \fB--recursive\fP option. This applies to all
294 \fB--file-list\fP, or by scanning a parent directory. The pattern is a PCRE2
296 name, not the entire path. The \fB-F\fP, \fB-w\fP, and \fB-x\fP options do not
298 specify more than one pattern. If a directory matches both \fB--include-dir\fP
299 and \fB--exclude-dir\fP, it is excluded. There is no short form for this
302 \fB-F\fP, \fB--fixed-strings\fP
303 Interpret each data-matching pattern as a list of fixed strings, separated by
305 this purpose is controlled by the \fB--newline\fP option. The \fB-w\fP (match
306 as a word) and \fB-x\fP (match whole line) options can be used with \fB-F\fP.
308 strings are found in it (subject to \fB-w\fP or \fB-x\fP, if present). This
310 files; it does not apply to patterns specified by any of the \fB--include\fP or
311 \fB--exclude\fP options.
313 \fB-f\fP \fIfilename\fP, \fB--file=\fP\fIfilename\fP
314 Read patterns from the file, one per line, and match them against each line of
316 be used. What constitutes a newline when reading the file is the operating
317 system's default interpretation of \en. The \fB--newline\fP option has no
319 blank lines are ignored. An empty file contains no patterns and therefore
320 matches nothing. Patterns read from a file in this way may contain binary
323 description of \fB-e\fP above.
326 data line is output if any of the patterns match it. A file name can be given
327 as "-" to refer to the standard input. When \fB-f\fP is used, patterns
328 specified on the command line using \fB-e\fP may also be present; they are
329 tested before the file's patterns. However, no other pattern is taken from the
332 \fB--file-list\fP=\fIfilename\fP
334 file, one per line. What constitutes a newline when reading the file is the
336 blank lines are ignored. These paths are processed before any that are listed
337 on the command line. The file name can be given as "-" to refer to the standard
338 input. If \fB--file\fP and \fB--file-list\fP are both specified as "-",
340 terminal, from which further lines (the list of files) can be read after an
341 end-of-file indication. If this option is given more than once, all the
344 \fB--file-offsets\fP
345 Instead of showing lines or parts of lines that match, show each match as an
346 offset from the start of the file and a length, separated by a comma. In this
347 mode, no context is shown. That is, the \fB-A\fP, \fB-B\fP, and \fB-C\fP
349 shown separately. This option is mutually exclusive with \fB--output\fP,
350 \fB--line-offsets\fP, and \fB--only-matching\fP.
352 \fB-H\fP, \fB--with-filename\fP
353 Force the inclusion of the file name at the start of output lines when
354 searching a single file. By default, the file name is not shown in this case.
355 For matching lines, the file name is followed by a colon; for context lines, a
357 file name. When the \fB-M\fP option causes a pattern to match more than one
358 line, only the first is preceded by the file name. This option overrides any
359 previous \fB-h\fP, \fB-l\fP, or \fB-L\fP options.
361 \fB-h\fP, \fB--no-filename\fP
362 Suppress the output file names when searching multiple files. By default,
363 file names are shown when multiple files are searched. For matching lines, the
364 file name is followed by a colon; for context lines, a hyphen separator is used.
365 If a line number is also being output, it follows the file name. This option
366 overrides any previous \fB-H\fP, \fB-L\fP, or \fB-l\fP options.
368 \fB--heap-limit\fP=\fInumber\fP
369 See \fB--match-limit\fP below.
371 \fB--help\fP
372 Output a help message, giving brief details of the command options and file
376 \fB-I\fP
378 \fB--binary-files\fP=\fIwithout-match\fP.
380 \fB-i\fP, \fB--ignore-case\fP
383 \fB--include\fP=\fIpattern\fP
384 If any \fB--include\fP patterns are specified, the only files that are
386 \fB--exclude\fP pattern. This option does not affect directories, but it
388 \fB--file-list\fP, or by scanning a directory. The pattern is a PCRE2 regular
389 expression, and is matched against the final component of the file name, not
390 the entire path. The \fB-F\fP, \fB-w\fP, and \fB-x\fP options do not apply to
391 this pattern. The option may be given any number of times. If a file name
392 matches both an \fB--include\fP and an \fB--exclude\fP pattern, it is excluded.
395 \fB--include-from=\fP\fIfilename\fP
396 Treat each non-empty line of the file as the data for an \fB--include\fP
398 default. The \fB--newline\fP option has no effect on this option. This option
401 \fB--include-dir\fP=\fIpattern\fP
402 If any \fB--include-dir\fP patterns are specified, the only directories that
404 an \fB--exclude-dir\fP pattern. This applies to all directories, whether listed
405 on the command line, obtained from \fB--file-list\fP, or by scanning a parent
407 the final component of the directory name, not the entire path. The \fB-F\fP,
408 \fB-w\fP, and \fB-x\fP options do not apply to this pattern. The option may be
409 given any number of times. If a directory matches both \fB--include-dir\fP and
410 \fB--exclude-dir\fP, it is excluded. There is no short form for this option.
412 \fB-L\fP, \fB--files-without-match\fP
413 Instead of outputting lines from the files, just output the names of the files
414 that do not contain any lines that would have been output. Each file name is
415 output once, on a separate line. This option overrides any previous \fB-H\fP,
416 \fB-h\fP, or \fB-l\fP options.
418 \fB-l\fP, \fB--files-with-matches\fP
419 Instead of outputting lines from the files, just output the names of the files
420 containing lines that would have been output. Each file name is output once, on
422 in a file. However, if the \fB-c\fP (count) option is also used, matching
425 \fB-c\fP is a way of suppressing the listing of files with no matches that
426 occurs with \fB-c\fP on its own. This option overrides any previous \fB-H\fP,
427 \fB-h\fP, or \fB-L\fP options.
429 \fB--label\fP=\fIname\fP
430 This option supplies a name to be used for the standard input when file names
434 \fB--line-buffered\fP
435 When this option is given, non-compressed input is read and processed line by
438 terminal, which is currently possible only in Unix-like environments or
442 However, its use will affect performance, and the \fB-M\fP (multiline) option
443 ceases to work. When input is from a compressed .gz or .bz2 file,
444 \fB--line-buffered\fP is ignored.
446 \fB--line-offsets\fP
447 Instead of showing lines or parts of lines that match, show each match as a
449 number is terminated by a colon (as usual; see the \fB-n\fP option), and the
451 That is, the \fB-A\fP, \fB-B\fP, and \fB-C\fP options are ignored. If there is
453 mutually exclusive with \fB--output\fP, \fB--file-offsets\fP, and
454 \fB--only-matching\fP.
456 \fB--locale\fP=\fIlocale-name\fP
462 \fB-M\fP, \fB--multiline\fP
465 past the end of a line and continue on one or more subsequent lines. Patterns
466 used with \fB-M\fP may usefully contain literal newline characters and internal
471 If \fB-v\fP is set, none of the lines in a multi-line match are output. Once a
475 The newline sequence that separates multiple lines must be matched as part of
476 the pattern. For example, to find the phrase "regular expression" in a file
480 pcre2grep -M 'regular\es+expression' <file>
484 well as possibly handling a two-character newline sequence.
486 There is a limit to the number of lines that can be matched, imposed by the way
487 that \fBpcre2grep\fP buffers the input file as it scans it. With a sufficiently
488 large processing buffer, this should not be a problem, but the \fB-M\fP option
489 does not work when input is read line by line (see \fB--line-buffered\fP.)
491 \fB-m\fP \fInumber\fP, \fB--max-count\fP=\fInumber\fP
492 Stop processing after finding \fInumber\fP matching lines, or non-matching
493 lines if \fB-v\fP is also set. Any trailing context lines are output after the
496 a regular file, the file is left positioned just after the last matching line.
497 If \fB-c\fP is also set, the count that is output is never greater than
498 \fInumber\fP. This option has no effect if used with \fB-L\fP, \fB-l\fP, or
499 \fB-q\fP, or when just checking for a match in a binary file.
501 \fB--match-limit\fP=\fInumber\fP
506 The \fB--match-limit\fP option provides a means of limiting computing resource
511 value set by \fB--match-limit\fP is reached, an error occurs.
513 The \fB--heap-limit\fP option specifies, as a number of kibibytes (units of
519 The \fB--depth-limit\fP option limits the depth of nested backtracking points,
524 set smaller than \fB--match-limit\fP.
530 \fB--max-buffer-size\fP=\fInumber\fP
532 set by \fB--buffer-size\fP. The maximum buffer size is silently forced to be no
535 \fB-N\fP \fInewline-type\fP, \fB--newline\fP=\fInewline-type\fP
536 Six different conventions for indicating the ends of lines in scanned files are
539 pcre2grep -N CRLF 'some pattern' <file>
542 newline type is NUL, lines are separated by binary zero characters. The other
543 types are the single-character sequences CR (carriage return) and LF
544 (linefeed), the two-character sequence CRLF, an "anycrlf" type, which
551 When the PCRE2 library is built, a default line-ending sequence is specified.
559 not apply to files specified by the \fB-f\fP, \fB--exclude-from\fP, or
560 \fB--include-from\fP options, which are expected to use the operating system's
563 \fB-n\fP, \fB--line-number\fP
564 Precede each output line by its line number in the file, followed by a colon
565 for matching lines or a hyphen for context lines. If the file name is also
566 being output, it precedes the line number. When the \fB-M\fP option causes a
568 number. This option is forced if \fB--line-offsets\fP is used.
570 \fB--no-jit\fP
571 If the PCRE2 library is built with support for just-in-time compiling (which
577 \fB-O\fP \fItext\fP, \fB--output\fP=\fItext\fP
579 the text specified in this option, followed by an operating-system standard
580 newline. In this mode, no context is shown. That is, the \fB-A\fP, \fB-B\fP,
581 and \fB-C\fP options are ignored. The \fB--newline\fP option has no effect on
582 this option, which is mutually exclusive with \fB--only-matching\fP,
583 \fB--file-offsets\fP, and \fB--line-offsets\fP. However, like
584 \fB--only-matching\fP, if there is more than one match in a line, each of them
612 \fB-o\fP, \fB--only-matching\fP
614 line. In this mode, no context is shown. That is, the \fB-A\fP, \fB-B\fP, and
615 \fB-C\fP options are ignored. If there is more than one match in a line, each
616 of them is shown separately, on a separate line of output. If \fB-o\fP is
617 combined with \fB-v\fP (invert the sense of the match to find non-matching
618 lines), no output is generated, but the return code is set appropriately. If
619 the matched portion of the line is empty, nothing is output unless the file
621 otherwise empty line. This option is mutually exclusive with \fB--output\fP,
622 \fB--file-offsets\fP and \fB--line-offsets\fP.
624 \fB-o\fP\fInumber\fP, \fB--only-matching\fP=\fInumber\fP
627 limit can be changed via the \fB--om-capture\fP option. A pattern may contain
629 limit can be accessed by \fB-o\fP. An error occurs if the number specified by
630 \fB-o\fP is greater than the limit.
632 -o0 is the same as \fB-o\fP without a number. Because these options can be
634 given in the same shell item, for example, -o3 or --only-matching=2. The
635 comments given for the non-argument case above also apply to this option. If
637 set in the match, nothing is output unless the file name or line number are
642 -o3 -o1 -o3 causes the substrings matched by capturing parentheses 3 and 1 and
646 \fB--om-capture\fP=\fInumber\fP
647 Set the number of capturing parentheses that can be accessed by \fB-o\fP. The
650 \fB--om-separator\fP=\fItext\fP
651 Specify a separating string for multiple occurrences of \fB-o\fP. The default
654 \fB-q\fP, \fB--quiet\fP
658 \fB-r\fP, \fB--recursive\fP
660 taking note of any \fB--include\fP and \fB--exclude\fP settings. By default, a
661 directory is read as a normal file; in some operating systems this gives an
662 immediate end-of-file. This option is a shorthand for setting the \fB-d\fP
665 \fB--recursion-limit\fP=\fInumber\fP
666 This is an obsolete synonym for \fB--depth-limit\fP. See \fB--match-limit\fP
669 \fB-s\fP, \fB--no-messages\fP
670 Suppress error messages about non-existent or unreadable files. Such files are
674 \fB-t\fP, \fB--total-count\fP
675 This option is useful when scanning more than one file. If used on its own,
676 \fB-t\fP suppresses all output except for a grand total number of matching
677 lines (or non-matching lines if \fB-v\fP is used) in all the files. If \fB-t\fP
678 is used with \fB-c\fP, a grand total is output except when the previous output
679 is just one line. In other words, it is not output when just one file's count
680 is listed. If file names are being output, the grand total is preceded by
681 "TOTAL:". Otherwise, it appears as just another number. The \fB-t\fP option is
682 ignored when used with \fB-L\fP (list files without matches), because the grand
685 \fB-u\fP, \fB--utf\fP
686 Operate in UTF-8 mode. This option is available only if PCRE2 has been compiled
687 with UTF-8 support. All patterns (including those for any \fB--exclude\fP and
688 \fB--include\fP options) and all lines that are scanned must be valid strings
689 of UTF-8 characters. If an invalid UTF-8 string is encountered, an error
692 \fB-U\fP, \fB--utf-allow-invalid\fP
693 As \fB--utf\fP, but in addition subject lines may contain invalid UTF-8 code
695 themselves, however, must still be valid UTF-8 strings. This facility allows
696 valid UTF-8 strings to be sought within arbitrary byte sequences in executable
697 or other binary files. For more details about matching in non-valid UTF-8
704 \fB-V\fP, \fB--version\fP
709 \fB-v\fP, \fB--invert-match\fP
710 Invert the sense of the match, so that lines which do \fInot\fP match any of
712 as \fB--only-matching\fP and \fB--output\fP, which specify parts of a match
715 \fB-w\fP, \fB--word-regex\fP, \fB--word-regexp\fP
720 files; it does not apply to patterns specified by any of the \fB--include\fP or
721 \fB--exclude\fP options.
723 \fB-x\fP, \fB--line-regex\fP, \fB--line-regexp\fP
724 Force the patterns to start matching only at the beginnings of lines, and in
725 addition, require them to match entire lines. In multiline mode the match may
729 by any of the \fB--include\fP or \fB--exclude\fP options.
737 by the \fB--locale\fP option. If no locale is set, the PCRE2 library's default
744 The \fB-N\fP (\fB--newline\fP) option allows \fBpcre2grep\fP to scan files with
747 specified by the \fB-f\fP, \fB--file-list\fP, \fB--exclude-from\fP, or
748 \fB--include-from\fP options.
752 the final line of a file is output, and it does not end with a newline
760 ends of output lines that are copied from the input is not converted to
771 \fB--xxx-regexp\fP (GNU terminology) is also available as \fB--xxx-regex\fP
772 (PCRE2 terminology). However, the \fB--depth-limit\fP, \fB--file-list\fP,
773 \fB--file-offsets\fP, \fB--heap-limit\fP, \fB--include-dir\fP,
774 \fB--line-offsets\fP, \fB--locale\fP, \fB--match-limit\fP, \fB-M\fP,
775 \fB--multiline\fP, \fB-N\fP, \fB--newline\fP, \fB--om-separator\fP,
776 \fB--output\fP, \fB-u\fP, \fB--utf\fP, \fB-U\fP, and \fB--utf-allow-invalid\fP
778 \fB--only-matching\fP option with a capturing parentheses number.
781 \fBpcre2grep\fP. For example, the \fB--include\fP option's argument is a glob
783 \fB-c\fP and \fB-l\fP options are given, GNU grep lists only file names,
794 -f/some/file
795 -f /some/file
797 The exception is the \fB-o\fP option, which may appear with or without data.
799 item, for example -o3.
805 --file=/some/file
806 --file /some/file
808 Note, however, that if you want to supply a file name beginning with ~ as data
810 separate the file name from the option, because the shell does not treat ~
813 The exceptions to the above are the \fB--colour\fP (or \fB--color\fP) and
814 \fB--only-matching\fP options, for which the data is optional. If one of these
826 for callouts by running it with the \fB--help\fP option. If callout support is
847 zero-terminated string, which means it should not contain any internal binary
849 escape processing as text from the \fB--output\fP (\fB-O\fP) option (see
857 pcre2grep '(.)(..(.))(?C"|[$1] [$2] [$3]$n")' <some file>
869 where \fBlib$spawn()\fP is used, and for any Unix-like environment where
880 started by a dollar character. These are the same as for the \fB--output\fP
881 (\fB-O\fP) option documented above, except that $0 cannot insert the matched
886 echo -e "abcde\en12345" | pcre2grep \e
888 (?C"/bin/echo|Arg1: [$1] [$2] [$3]|Arg2: $|${1}$| ($4)")()' -
898 are zero-terminated strings. This means that binary zero characters in the
902 If running the program fails for any reason (including the non-existence of the
911 fail to match certain lines. Such patterns normally involve nested indefinite
918 The \fB--match-limit\fP option of \fBpcre2grep\fP can be used to set the
920 memory used during matching; see the discussion of \fB--heap-limit\fP and
921 \fB--depth-limit\fP above.
928 for syntax errors, overlong lines, non-existent or inaccessible files (even if
930 \fB-s\fP option to suppress error messages about inaccessible files does not
959 Copyright (c) 1997-2020 University of Cambridge.