blob: 6ee4cc6a008fa80623fcf076cd59ce9b123042ad [file] [log] [blame]
Tristan Matthews04616462013-11-14 16:09:34 -05001.TH PCREGREP 1
2.SH NAME
3pcregrep - a grep with Perl-compatible regular expressions.
4.SH SYNOPSIS
5.B pcregrep [options] [long options] [pattern] [path1 path2 ...]
6.
7.SH DESCRIPTION
8.rs
9.sp
10\fBpcregrep\fP searches files for character patterns, in the same way as other
11grep commands do, but it uses the PCRE regular expression library to support
12patterns that are compatible with the regular expressions of Perl 5. See
13.\" HREF
14\fBpcrepattern\fP(3)
15.\"
16for a full description of syntax and semantics of the regular expressions
17that PCRE supports.
18.P
19Patterns, whether supplied on the command line or in a separate file, are given
20without delimiters. For example:
21.sp
22 pcregrep Thursday /etc/motd
23.sp
24If you attempt to use delimiters (for example, by surrounding a pattern with
25slashes, as is common in Perl scripts), they are interpreted as part of the
26pattern. Quotes can of course be used to delimit patterns on the command line
27because they are interpreted by the shell, and indeed they are required if a
28pattern contains white space or shell metacharacters.
29.P
30The first argument that follows any option settings is treated as the single
31pattern to be matched when neither \fB-e\fP nor \fB-f\fP is present.
32Conversely, when one or both of these options are used to specify patterns, all
33arguments are treated as path names. At least one of \fB-e\fP, \fB-f\fP, or an
34argument pattern must be provided.
35.P
36If no files are specified, \fBpcregrep\fP reads the standard input. The
37standard input can also be referenced by a name consisting of a single hyphen.
38For example:
39.sp
40 pcregrep some-pattern /file1 - /file3
41.sp
42By default, each line that matches a pattern is copied to the standard
43output, and if there is more than one file, the file name is output at the
44start of each line, followed by a colon. However, there are options that can
45change how \fBpcregrep\fP behaves. In particular, the \fB-M\fP option makes it
46possible to search for patterns that span line boundaries. What defines a line
47boundary is controlled by the \fB-N\fP (\fB--newline\fP) option.
48.P
49The amount of memory used for buffering files that are being scanned is
50controlled by a parameter that can be set by the \fB--buffer-size\fP option.
51The default value for this parameter is specified when \fBpcregrep\fP is built,
52with the default default being 20K. A block of memory three times this size is
53used (to allow for buffering "before" and "after" lines). An error occurs if a
54line overflows the buffer.
55.P
56Patterns are limited to 8K or BUFSIZ bytes, whichever is the greater. BUFSIZ is
57defined in \fB<stdio.h>\fP. When there is more than one pattern (specified by
58the use of \fB-e\fP and/or \fB-f\fP), each pattern is applied to each line in
59the order in which they are defined, except that all the \fB-e\fP patterns are
60tried before the \fB-f\fP patterns.
61.P
62By default, as soon as one pattern matches (or fails to match when \fB-v\fP is
63used), no further patterns are considered. However, if \fB--colour\fP (or
64\fB--color\fP) is used to colour the matching substrings, or if
65\fB--only-matching\fP, \fB--file-offsets\fP, or \fB--line-offsets\fP is used to
66output only the part of the line that matched (either shown literally, or as an
67offset), scanning resumes immediately following the match, so that further
68matches on the same line can be found. If there are multiple patterns, they are
69all tried on the remainder of the line, but patterns that follow the one that
70matched are not tried on the earlier part of the line.
71.P
72This is the same behaviour as GNU grep, but it does mean that the order in
73which multiple patterns are specified can affect the output when one of the
74above options is used.
75.P
76Patterns that can match an empty string are accepted, but empty string
77matches are never recognized. An example is the pattern "(super)?(man)?", in
78which all components are optional. This pattern finds all occurrences of both
79"super" and "man"; the output differs from matching with "super|man" when only
80the matching substrings are being shown.
81.P
82If the \fBLC_ALL\fP or \fBLC_CTYPE\fP environment variable is set,
83\fBpcregrep\fP uses the value to set a locale when calling the PCRE library.
84The \fB--locale\fP option can be used to override this.
85.
86.
87.SH "SUPPORT FOR COMPRESSED FILES"
88.rs
89.sp
90It is possible to compile \fBpcregrep\fP so that it uses \fBlibz\fP or
91\fBlibbz2\fP to read files whose names end in \fB.gz\fP or \fB.bz2\fP,
92respectively. You can find out whether your binary has support for one or both
93of these file types by running it with the \fB--help\fP option. If the
94appropriate support is not present, files are treated as plain text. The
95standard input is always so treated.
96.
97.
98.SH OPTIONS
99.rs
100.sp
101The order in which some of the options appear can affect the output. For
102example, both the \fB-h\fP and \fB-l\fP options affect the printing of file
103names. Whichever comes later in the command line will be the one that takes
104effect. Numerical values for options may be followed by K or M, to signify
105multiplication by 1024 or 1024*1024 respectively.
106.TP 10
107\fB--\fP
108This terminates the list of options. It is useful if the next item on the
109command line starts with a hyphen but is not an option. This allows for the
110processing of patterns and filenames that start with hyphens.
111.TP
112\fB-A\fP \fInumber\fP, \fB--after-context=\fP\fInumber\fP
113Output \fInumber\fP lines of context after each matching line. If filenames
114and/or line numbers are being output, a hyphen separator is used instead of a
115colon for the context lines. A line containing "--" is output between each
116group of lines, unless they are in fact contiguous in the input file. The value
117of \fInumber\fP is expected to be relatively small. However, \fBpcregrep\fP
118guarantees to have up to 8K of following text available for context output.
119.TP
120\fB-B\fP \fInumber\fP, \fB--before-context=\fP\fInumber\fP
121Output \fInumber\fP lines of context before each matching line. If filenames
122and/or line numbers are being output, a hyphen separator is used instead of a
123colon for the context lines. A line containing "--" is output between each
124group of lines, unless they are in fact contiguous in the input file. The value
125of \fInumber\fP is expected to be relatively small. However, \fBpcregrep\fP
126guarantees to have up to 8K of preceding text available for context output.
127.TP
128\fB--buffer-size=\fP\fInumber\fP
129Set the parameter that controls how much memory is used for buffering files
130that are being scanned.
131.TP
132\fB-C\fP \fInumber\fP, \fB--context=\fP\fInumber\fP
133Output \fInumber\fP lines of context both before and after each matching line.
134This is equivalent to setting both \fB-A\fP and \fB-B\fP to the same value.
135.TP
136\fB-c\fP, \fB--count\fP
137Do not output individual lines from the files that are being scanned; instead
138output the number of lines that would otherwise have been shown. If no lines
139are selected, the number zero is output. If several files are are being
140scanned, a count is output for each of them. However, if the
141\fB--files-with-matches\fP option is also used, only those files whose counts
142are greater than zero are listed. When \fB-c\fP is used, the \fB-A\fP,
143\fB-B\fP, and \fB-C\fP options are ignored.
144.TP
145\fB--colour\fP, \fB--color\fP
146If this option is given without any data, it is equivalent to "--colour=auto".
147If data is required, it must be given in the same shell item, separated by an
148equals sign.
149.TP
150\fB--colour=\fP\fIvalue\fP, \fB--color=\fP\fIvalue\fP
151This option specifies under what circumstances the parts of a line that matched
152a pattern should be coloured in the output. By default, the output is not
153coloured. The value (which is optional, see above) may be "never", "always", or
154"auto". In the latter case, colouring happens only if the standard output is
155connected to a terminal. More resources are used when colouring is enabled,
156because \fBpcregrep\fP has to search for all possible matches in a line, not
157just one, in order to colour them all.
158.sp
159The colour that is used can be specified by setting the environment variable
160PCREGREP_COLOUR or PCREGREP_COLOR. The value of this variable should be a
161string of two numbers, separated by a semicolon. They are copied directly into
162the control string for setting colour on a terminal, so it is your
163responsibility to ensure that they make sense. If neither of the environment
164variables is set, the default is "1;31", which gives red.
165.TP
166\fB-D\fP \fIaction\fP, \fB--devices=\fP\fIaction\fP
167If an input path is not a regular file or a directory, "action" specifies how
168it is to be processed. Valid values are "read" (the default) or "skip"
169(silently skip the path).
170.TP
171\fB-d\fP \fIaction\fP, \fB--directories=\fP\fIaction\fP
172If an input path is a directory, "action" specifies how it is to be processed.
173Valid values are "read" (the default), "recurse" (equivalent to the \fB-r\fP
174option), or "skip" (silently skip the path). In the default case, directories
175are read as if they were ordinary files. In some operating systems the effect
176of reading a directory like this is an immediate end-of-file.
177.TP
178\fB-e\fP \fIpattern\fP, \fB--regex=\fP\fIpattern\fP, \fB--regexp=\fP\fIpattern\fP
179Specify a pattern to be matched. This option can be used multiple times in
180order to specify several patterns. It can also be used as a way of specifying a
181single pattern that starts with a hyphen. When \fB-e\fP is used, no argument
182pattern is taken from the command line; all arguments are treated as file
183names. There is an overall maximum of 100 patterns. They are applied to each
184line in the order in which they are defined until one matches (or fails to
185match if \fB-v\fP is used). If \fB-f\fP is used with \fB-e\fP, the command line
186patterns are matched first, followed by the patterns from the file, independent
187of the order in which these options are specified. Note that multiple use of
188\fB-e\fP is not the same as a single pattern with alternatives. For example,
189X|Y finds the first character in a line that is X or Y, whereas if the two
190patterns are given separately, \fBpcregrep\fP finds X if it is present, even if
191it follows Y in the line. It finds Y only if there is no X in the line. This
192really matters only if you are using \fB-o\fP to show the part(s) of the line
193that matched.
194.TP
195\fB--exclude\fP=\fIpattern\fP
196When \fBpcregrep\fP is searching the files in a directory as a consequence of
197the \fB-r\fP (recursive search) option, any regular files whose names match the
198pattern are excluded. Subdirectories are not excluded by this option; they are
199searched recursively, subject to the \fB--exclude-dir\fP and
200\fB--include_dir\fP options. The pattern is a PCRE regular expression, and is
201matched against the final component of the file name (not the entire path). If
202a file name matches both \fB--include\fP and \fB--exclude\fP, it is excluded.
203There is no short form for this option.
204.TP
205\fB--exclude-dir\fP=\fIpattern\fP
206When \fBpcregrep\fP is searching the contents of a directory as a consequence
207of the \fB-r\fP (recursive search) option, any subdirectories whose names match
208the pattern are excluded. (Note that the \fP--exclude\fP option does not affect
209subdirectories.) The pattern is a PCRE regular expression, and is matched
210against the final component of the name (not the entire path). If a
211subdirectory name matches both \fB--include-dir\fP and \fB--exclude-dir\fP, it
212is excluded. There is no short form for this option.
213.TP
214\fB-F\fP, \fB--fixed-strings\fP
215Interpret each pattern as a list of fixed strings, separated by newlines,
216instead of as a regular expression. The \fB-w\fP (match as a word) and \fB-x\fP
217(match whole line) options can be used with \fB-F\fP. They apply to each of the
218fixed strings. A line is selected if any of the fixed strings are found in it
219(subject to \fB-w\fP or \fB-x\fP, if present).
220.TP
221\fB-f\fP \fIfilename\fP, \fB--file=\fP\fIfilename\fP
222Read a number of patterns from the file, one per line, and match them against
223each line of input. A data line is output if any of the patterns match it. The
224filename can be given as "-" to refer to the standard input. When \fB-f\fP is
225used, patterns specified on the command line using \fB-e\fP may also be
226present; they are tested before the file's patterns. However, no other pattern
227is taken from the command line; all arguments are treated as file names. There
228is an overall maximum of 100 patterns. Trailing white space is removed from
229each line, and blank lines are ignored. An empty file contains no patterns and
230therefore matches nothing. See also the comments about multiple patterns versus
231a single pattern with alternatives in the description of \fB-e\fP above.
232.TP
233\fB--file-offsets\fP
234Instead of showing lines or parts of lines that match, show each match as an
235offset from the start of the file and a length, separated by a comma. In this
236mode, no context is shown. That is, the \fB-A\fP, \fB-B\fP, and \fB-C\fP
237options are ignored. If there is more than one match in a line, each of them is
238shown separately. This option is mutually exclusive with \fB--line-offsets\fP
239and \fB--only-matching\fP.
240.TP
241\fB-H\fP, \fB--with-filename\fP
242Force the inclusion of the filename at the start of output lines when searching
243a single file. By default, the filename is not shown in this case. For matching
244lines, the filename is followed by a colon; for context lines, a hyphen
245separator is used. If a line number is also being output, it follows the file
246name.
247.TP
248\fB-h\fP, \fB--no-filename\fP
249Suppress the output filenames when searching multiple files. By default,
250filenames are shown when multiple files are searched. For matching lines, the
251filename is followed by a colon; for context lines, a hyphen separator is used.
252If a line number is also being output, it follows the file name.
253.TP
254\fB--help\fP
255Output a help message, giving brief details of the command options and file
256type support, and then exit.
257.TP
258\fB-i\fP, \fB--ignore-case\fP
259Ignore upper/lower case distinctions during comparisons.
260.TP
261\fB--include\fP=\fIpattern\fP
262When \fBpcregrep\fP is searching the files in a directory as a consequence of
263the \fB-r\fP (recursive search) option, only those regular files whose names
264match the pattern are included. Subdirectories are always included and searched
265recursively, subject to the \fP--include-dir\fP and \fB--exclude-dir\fP
266options. The pattern is a PCRE regular expression, and is matched against the
267final component of the file name (not the entire path). If a file name matches
268both \fB--include\fP and \fB--exclude\fP, it is excluded. There is no short
269form for this option.
270.TP
271\fB--include-dir\fP=\fIpattern\fP
272When \fBpcregrep\fP is searching the contents of a directory as a consequence
273of the \fB-r\fP (recursive search) option, only those subdirectories whose
274names match the pattern are included. (Note that the \fB--include\fP option
275does not affect subdirectories.) The pattern is a PCRE regular expression, and
276is matched against the final component of the name (not the entire path). If a
277subdirectory name matches both \fB--include-dir\fP and \fB--exclude-dir\fP, it
278is excluded. There is no short form for this option.
279.TP
280\fB-L\fP, \fB--files-without-match\fP
281Instead of outputting lines from the files, just output the names of the files
282that do not contain any lines that would have been output. Each file name is
283output once, on a separate line.
284.TP
285\fB-l\fP, \fB--files-with-matches\fP
286Instead of outputting lines from the files, just output the names of the files
287containing lines that would have been output. Each file name is output
288once, on a separate line. Searching normally stops as soon as a matching line
289is found in a file. However, if the \fB-c\fP (count) option is also used,
290matching continues in order to obtain the correct count, and those files that
291have at least one match are listed along with their counts. Using this option
292with \fB-c\fP is a way of suppressing the listing of files with no matches.
293.TP
294\fB--label\fP=\fIname\fP
295This option supplies a name to be used for the standard input when file names
296are being output. If not supplied, "(standard input)" is used. There is no
297short form for this option.
298.TP
299\fB--line-buffered\fP
300When this option is given, input is read and processed line by line, and the
301output is flushed after each write. By default, input is read in large chunks,
302unless \fBpcregrep\fP can determine that it is reading from a terminal (which
303is currently possible only in Unix environments). Output to terminal is
304normally automatically flushed by the operating system. This option can be
305useful when the input or output is attached to a pipe and you do not want
306\fBpcregrep\fP to buffer up large amounts of data. However, its use will affect
307performance, and the \fB-M\fP (multiline) option ceases to work.
308.TP
309\fB--line-offsets\fP
310Instead of showing lines or parts of lines that match, show each match as a
311line number, the offset from the start of the line, and a length. The line
312number is terminated by a colon (as usual; see the \fB-n\fP option), and the
313offset and length are separated by a comma. In this mode, no context is shown.
314That is, the \fB-A\fP, \fB-B\fP, and \fB-C\fP options are ignored. If there is
315more than one match in a line, each of them is shown separately. This option is
316mutually exclusive with \fB--file-offsets\fP and \fB--only-matching\fP.
317.TP
318\fB--locale\fP=\fIlocale-name\fP
319This option specifies a locale to be used for pattern matching. It overrides
320the value in the \fBLC_ALL\fP or \fBLC_CTYPE\fP environment variables. If no
321locale is specified, the PCRE library's default (usually the "C" locale) is
322used. There is no short form for this option.
323.TP
324\fB--match-limit\fP=\fInumber\fP
325Processing some regular expression patterns can require a very large amount of
326memory, leading in some cases to a program crash if not enough is available.
327Other patterns may take a very long time to search for all possible matching
328strings. The \fBpcre_exec()\fP function that is called by \fBpcregrep\fP to do
329the matching has two parameters that can limit the resources that it uses.
330.sp
331The \fB--match-limit\fP option provides a means of limiting resource usage
332when processing patterns that are not going to match, but which have a very
333large number of possibilities in their search trees. The classic example is a
334pattern that uses nested unlimited repeats. Internally, PCRE uses a function
335called \fBmatch()\fP which it calls repeatedly (sometimes recursively). The
336limit set by \fB--match-limit\fP is imposed on the number of times this
337function is called during a match, which has the effect of limiting the amount
338of backtracking that can take place.
339.sp
340The \fB--recursion-limit\fP option is similar to \fB--match-limit\fP, but
341instead of limiting the total number of times that \fBmatch()\fP is called, it
342limits the depth of recursive calls, which in turn limits the amount of memory
343that can be used. The recursion depth is a smaller number than the total number
344of calls, because not all calls to \fBmatch()\fP are recursive. This limit is
345of use only if it is set smaller than \fB--match-limit\fP.
346.sp
347There are no short forms for these options. The default settings are specified
348when the PCRE library is compiled, with the default default being 10 million.
349.TP
350\fB-M\fP, \fB--multiline\fP
351Allow patterns to match more than one line. When this option is given, patterns
352may usefully contain literal newline characters and internal occurrences of ^
353and $ characters. The output for a successful match may consist of more than
354one line, the last of which is the one in which the match ended. If the matched
355string ends with a newline sequence the output ends at the end of that line.
356.sp
357When this option is set, the PCRE library is called in "multiline" mode.
358There is a limit to the number of lines that can be matched, imposed by the way
359that \fBpcregrep\fP buffers the input file as it scans it. However,
360\fBpcregrep\fP ensures that at least 8K characters or the rest of the document
361(whichever is the shorter) are available for forward matching, and similarly
362the previous 8K characters (or all the previous characters, if fewer than 8K)
363are guaranteed to be available for lookbehind assertions. This option does not
364work when input is read line by line (see \fP--line-buffered\fP.)
365.TP
366\fB-N\fP \fInewline-type\fP, \fB--newline\fP=\fInewline-type\fP
367The PCRE library supports five different conventions for indicating
368the ends of lines. They are the single-character sequences CR (carriage return)
369and LF (linefeed), the two-character sequence CRLF, an "anycrlf" convention,
370which recognizes any of the preceding three types, and an "any" convention, in
371which any Unicode line ending sequence is assumed to end a line. The Unicode
372sequences are the three just mentioned, plus VT (vertical tab, U+000B), FF
373(form feed, U+000C), NEL (next line, U+0085), LS (line separator, U+2028), and
374PS (paragraph separator, U+2029).
375.sp
376When the PCRE library is built, a default line-ending sequence is specified.
377This is normally the standard sequence for the operating system. Unless
378otherwise specified by this option, \fBpcregrep\fP uses the library's default.
379The possible values for this option are CR, LF, CRLF, ANYCRLF, or ANY. This
380makes it possible to use \fBpcregrep\fP on files that have come from other
381environments without having to modify their line endings. If the data that is
382being scanned does not agree with the convention set by this option,
383\fBpcregrep\fP may behave in strange ways.
384.TP
385\fB-n\fP, \fB--line-number\fP
386Precede each output line by its line number in the file, followed by a colon
387for matching lines or a hyphen for context lines. If the filename is also being
388output, it precedes the line number. This option is forced if
389\fB--line-offsets\fP is used.
390.TP
391\fB--no-jit\fP
392If the PCRE library is built with support for just-in-time compiling (which
393speeds up matching), \fBpcregrep\fP automatically makes use of this, unless it
394was explicitly disabled at build time. This option can be used to disable the
395use of JIT at run time. It is provided for testing and working round problems.
396It should never be needed in normal use.
397.TP
398\fB-o\fP, \fB--only-matching\fP
399Show only the part of the line that matched a pattern instead of the whole
400line. In this mode, no context is shown. That is, the \fB-A\fP, \fB-B\fP, and
401\fB-C\fP options are ignored. If there is more than one match in a line, each
402of them is shown separately. If \fB-o\fP is combined with \fB-v\fP (invert the
403sense of the match to find non-matching lines), no output is generated, but the
404return code is set appropriately. If the matched portion of the line is empty,
405nothing is output unless the file name or line number are being printed, in
406which case they are shown on an otherwise empty line. This option is mutually
407exclusive with \fB--file-offsets\fP and \fB--line-offsets\fP.
408.TP
409\fB-o\fP\fInumber\fP, \fB--only-matching\fP=\fInumber\fP
410Show only the part of the line that matched the capturing parentheses of the
411given number. Up to 32 capturing parentheses are supported. Because these
412options can be given without an argument (see above), if an argument is
413present, it must be given in the same shell item, for example, -o3 or
414--only-matching=2. The comments given for the non-argument case above also
415apply to this case. If the specified capturing parentheses do not exist in the
416pattern, or were not set in the match, nothing is output unless the file name
417or line number are being printed.
418.TP
419\fB-q\fP, \fB--quiet\fP
420Work quietly, that is, display nothing except error messages. The exit
421status indicates whether or not any matches were found.
422.TP
423\fB-r\fP, \fB--recursive\fP
424If any given path is a directory, recursively scan the files it contains,
425taking note of any \fB--include\fP and \fB--exclude\fP settings. By default, a
426directory is read as a normal file; in some operating systems this gives an
427immediate end-of-file. This option is a shorthand for setting the \fB-d\fP
428option to "recurse".
429.TP
430\fB--recursion-limit\fP=\fInumber\fP
431See \fB--match-limit\fP above.
432.TP
433\fB-s\fP, \fB--no-messages\fP
434Suppress error messages about non-existent or unreadable files. Such files are
435quietly skipped. However, the return code is still 2, even if matches were
436found in other files.
437.TP
438\fB-u\fP, \fB--utf-8\fP
439Operate in UTF-8 mode. This option is available only if PCRE has been compiled
440with UTF-8 support. Both patterns and subject lines must be valid strings of
441UTF-8 characters.
442.TP
443\fB-V\fP, \fB--version\fP
444Write the version numbers of \fBpcregrep\fP and the PCRE library that is being
445used to the standard error stream.
446.TP
447\fB-v\fP, \fB--invert-match\fP
448Invert the sense of the match, so that lines which do \fInot\fP match any of
449the patterns are the ones that are found.
450.TP
451\fB-w\fP, \fB--word-regex\fP, \fB--word-regexp\fP
452Force the patterns to match only whole words. This is equivalent to having \eb
453at the start and end of the pattern.
454.TP
455\fB-x\fP, \fB--line-regex\fP, \fB--line-regexp\fP
456Force the patterns to be anchored (each must start matching at the beginning of
457a line) and in addition, require them to match entire lines. This is
458equivalent to having ^ and $ characters at the start and end of each
459alternative branch in every pattern.
460.
461.
462.SH "ENVIRONMENT VARIABLES"
463.rs
464.sp
465The environment variables \fBLC_ALL\fP and \fBLC_CTYPE\fP are examined, in that
466order, for a locale. The first one that is set is used. This can be overridden
467by the \fB--locale\fP option. If no locale is set, the PCRE library's default
468(usually the "C" locale) is used.
469.
470.
471.SH "NEWLINES"
472.rs
473.sp
474The \fB-N\fP (\fB--newline\fP) option allows \fBpcregrep\fP to scan files with
475different newline conventions from the default. However, the setting of this
476option does not affect the way in which \fBpcregrep\fP writes information to
477the standard error and output streams. It uses the string "\en" in C
478\fBprintf()\fP calls to indicate newlines, relying on the C I/O library to
479convert this to an appropriate sequence if the output is sent to a file.
480.
481.
482.SH "OPTIONS COMPATIBILITY"
483.rs
484.sp
485Many of the short and long forms of \fBpcregrep\fP's options are the same
486as in the GNU \fBgrep\fP program (version 2.5.4). Any long option of the form
487\fB--xxx-regexp\fP (GNU terminology) is also available as \fB--xxx-regex\fP
488(PCRE terminology). However, the \fB--file-offsets\fP, \fB--include-dir\fP,
489\fB--line-offsets\fP, \fB--locale\fP, \fB--match-limit\fP, \fB-M\fP,
490\fB--multiline\fP, \fB-N\fP, \fB--newline\fP, \fB--recursion-limit\fP,
491\fB-u\fP, and \fB--utf-8\fP options are specific to \fBpcregrep\fP, as is the
492use of the \fB--only-matching\fP option with a capturing parentheses number.
493.P
494Although most of the common options work the same way, a few are different in
495\fBpcregrep\fP. For example, the \fB--include\fP option's argument is a glob
496for GNU \fBgrep\fP, but a regular expression for \fBpcregrep\fP. If both the
497\fB-c\fP and \fB-l\fP options are given, GNU grep lists only file names,
498without counts, but \fBpcregrep\fP gives the counts.
499.
500.
501.SH "OPTIONS WITH DATA"
502.rs
503.sp
504There are four different ways in which an option with data can be specified.
505If a short form option is used, the data may follow immediately, or (with one
506exception) in the next command line item. For example:
507.sp
508 -f/some/file
509 -f /some/file
510.sp
511The exception is the \fB-o\fP option, which may appear with or without data.
512Because of this, if data is present, it must follow immediately in the same
513item, for example -o3.
514.P
515If a long form option is used, the data may appear in the same command line
516item, separated by an equals character, or (with two exceptions) it may appear
517in the next command line item. For example:
518.sp
519 --file=/some/file
520 --file /some/file
521.sp
522Note, however, that if you want to supply a file name beginning with ~ as data
523in a shell command, and have the shell expand ~ to a home directory, you must
524separate the file name from the option, because the shell does not treat ~
525specially unless it is at the start of an item.
526.P
527The exceptions to the above are the \fB--colour\fP (or \fB--color\fP) and
528\fB--only-matching\fP options, for which the data is optional. If one of these
529options does have data, it must be given in the first form, using an equals
530character. Otherwise \fBpcregrep\fP will assume that it has no data.
531.
532.
533.SH "MATCHING ERRORS"
534.rs
535.sp
536It is possible to supply a regular expression that takes a very long time to
537fail to match certain lines. Such patterns normally involve nested indefinite
538repeats, for example: (a+)*\ed when matched against a line of a's with no final
539digit. The PCRE matching function has a resource limit that causes it to abort
540in these circumstances. If this happens, \fBpcregrep\fP outputs an error
541message and the line that caused the problem to the standard error stream. If
542there are more than 20 such errors, \fBpcregrep\fP gives up.
543.P
544The \fB--match-limit\fP option of \fBpcregrep\fP can be used to set the overall
545resource limit; there is a second option called \fB--recursion-limit\fP that
546sets a limit on the amount of memory (usually stack) that is used (see the
547discussion of these options above).
548.
549.
550.SH DIAGNOSTICS
551.rs
552.sp
553Exit status is 0 if any matches were found, 1 if no matches were found, and 2
554for syntax errors, overlong lines, non-existent or inaccessible files (even if
555matches were found in other files) or too many matching errors. Using the
556\fB-s\fP option to suppress error messages about inaccessible files does not
557affect the return code.
558.
559.
560.SH "SEE ALSO"
561.rs
562.sp
563\fBpcrepattern\fP(3), \fBpcretest\fP(1).
564.
565.
566.SH AUTHOR
567.rs
568.sp
569.nf
570Philip Hazel
571University Computing Service
572Cambridge CB2 3QH, England.
573.fi
574.
575.
576.SH REVISION
577.rs
578.sp
579.nf
580Last updated: 06 September 2011
581Copyright (c) 1997-2011 University of Cambridge.
582.fi