/[pcre]/code/trunk/doc/pcregrep.1
ViewVC logotype

Contents of /code/trunk/doc/pcregrep.1

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:eol-style native
svn:keywords "Author Date Id Revision Url"

  ViewVC Help
Powered by ViewVC 1.1.5