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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 572 - (hide annotations) (download)
Wed Nov 17 17:55:57 2010 UTC (4 years ago) by ph10
File MIME type: text/plain
File size: 33950 byte(s)
Documentation updates and tidies.

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

Properties

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

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12