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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.5