/[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 87 - (show annotations) (download) (as text)
Sat Feb 24 21:41:21 2007 UTC (7 years, 4 months ago) by nigel
File MIME type: text/html
File size: 18006 byte(s)
Load pcre-6.5 into code/trunk.

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">OPTIONS</a>
19 <li><a name="TOC4" href="#SEC4">ENVIRONMENT VARIABLES</a>
20 <li><a name="TOC5" href="#SEC5">OPTIONS COMPATIBILITY</a>
21 <li><a name="TOC6" href="#SEC6">OPTIONS WITH DATA</a>
22 <li><a name="TOC7" href="#SEC7">MATCHING ERRORS</a>
23 <li><a name="TOC8" href="#SEC8">DIAGNOSTICS</a>
24 <li><a name="TOC9" href="#SEC9">AUTHOR</a>
25 </ul>
26 <br><a name="SEC1" href="#TOC1">SYNOPSIS</a><br>
27 <P>
28 <b>pcregrep [options] [long options] [pattern] [path1 path2 ...]</b>
29 </P>
30 <br><a name="SEC2" href="#TOC1">DESCRIPTION</a><br>
31 <P>
32 <b>pcregrep</b> searches files for character patterns, in the same way as other
33 grep commands do, but it uses the PCRE regular expression library to support
34 patterns that are compatible with the regular expressions of Perl 5. See
35 <a href="pcrepattern.html"><b>pcrepattern</b></a>
36 for a full description of syntax and semantics of the regular expressions that
37 PCRE supports.
38 </P>
39 <P>
40 Patterns, whether supplied on the command line or in a separate file, are given
41 without delimiters. For example:
42 <pre>
43 pcregrep Thursday /etc/motd
44 </pre>
45 If you attempt to use delimiters (for example, by surrounding a pattern with
46 slashes, as is common in Perl scripts), they are interpreted as part of the
47 pattern. Quotes can of course be used on the command line because they are
48 interpreted by the shell, and indeed they are required if a pattern contains
49 white space or shell metacharacters.
50 </P>
51 <P>
52 The first argument that follows any option settings is treated as the single
53 pattern to be matched when neither <b>-e</b> nor <b>-f</b> is present.
54 Conversely, when one or both of these options are used to specify patterns, all
55 arguments are treated as path names. At least one of <b>-e</b>, <b>-f</b>, or an
56 argument pattern must be provided.
57 </P>
58 <P>
59 If no files are specified, <b>pcregrep</b> reads the standard input. The
60 standard input can also be referenced by a name consisting of a single hyphen.
61 For example:
62 <pre>
63 pcregrep some-pattern /file1 - /file3
64 </pre>
65 By default, each line that matches the pattern is copied to the standard
66 output, and if there is more than one file, the file name is output at the
67 start of each line. However, there are options that can change how
68 <b>pcregrep</b> behaves. In particular, the <b>-M</b> option makes it possible to
69 search for patterns that span line boundaries.
70 </P>
71 <P>
72 Patterns are limited to 8K or BUFSIZ characters, whichever is the greater.
73 BUFSIZ is defined in <b>&#60;stdio.h&#62;</b>.
74 </P>
75 <P>
76 If the <b>LC_ALL</b> or <b>LC_CTYPE</b> environment variable is set,
77 <b>pcregrep</b> uses the value to set a locale when calling the PCRE library.
78 The <b>--locale</b> option can be used to override this.
79 </P>
80 <br><a name="SEC3" href="#TOC1">OPTIONS</a><br>
81 <P>
82 <b>--</b>
83 This terminate the list of options. It is useful if the next item on the
84 command line starts with a hyphen but is not an option. This allows for the
85 processing of patterns and filenames that start with hyphens.
86 </P>
87 <P>
88 <b>-A</b> <i>number</i>, <b>--after-context=</b><i>number</i>
89 Output <i>number</i> lines of context after each matching line. If filenames
90 and/or line numbers are being output, a hyphen separator is used instead of a
91 colon for the context lines. A line containing "--" is output between each
92 group of lines, unless they are in fact contiguous in the input file. The value
93 of <i>number</i> is expected to be relatively small. However, <b>pcregrep</b>
94 guarantees to have up to 8K of following text available for context output.
95 </P>
96 <P>
97 <b>-B</b> <i>number</i>, <b>--before-context=</b><i>number</i>
98 Output <i>number</i> lines of context before each matching line. If filenames
99 and/or line numbers are being output, a hyphen separator is used instead of a
100 colon for the context lines. A line containing "--" is output between each
101 group of lines, unless they are in fact contiguous in the input file. The value
102 of <i>number</i> is expected to be relatively small. However, <b>pcregrep</b>
103 guarantees to have up to 8K of preceding text available for context output.
104 </P>
105 <P>
106 <b>-C</b> <i>number</i>, <b>--context=</b><i>number</i>
107 Output <i>number</i> lines of context both before and after each matching line.
108 This is equivalent to setting both <b>-A</b> and <b>-B</b> to the same value.
109 </P>
110 <P>
111 <b>-c</b>, <b>--count</b>
112 Do not output individual lines; instead just output a count of the number of
113 lines that would otherwise have been output. If several files are given, a
114 count is output for each of them. In this mode, the <b>-A</b>, <b>-B</b>, and
115 <b>-C</b> options are ignored.
116 </P>
117 <P>
118 <b>--colour</b>, <b>--color</b>
119 If this option is given without any data, it is equivalent to "--colour=auto".
120 If data is required, it must be given in the same shell item, separated by an
121 equals sign.
122 </P>
123 <P>
124 <b>--colour=</b><i>value</i>, <b>--color=</b><i>value</i>
125 This option specifies under what circumstances the part of a line that matched
126 a pattern should be coloured in the output. The value may be "never" (the
127 default), "always", or "auto". In the latter case, colouring happens only if
128 the standard output is connected to a terminal. The colour can be specified by
129 setting the environment variable PCREGREP_COLOUR or PCREGREP_COLOR. The value
130 of this variable should be a string of two numbers, separated by a semicolon.
131 They are copied directly into the control string for setting colour on a
132 terminal, so it is your responsibility to ensure that they make sense. If
133 neither of the environment variables is set, the default is "1;31", which gives
134 red.
135 </P>
136 <P>
137 <b>-D</b> <i>action</i>, <b>--devices=</b><i>action</i>
138 If an input path is not a regular file or a directory, "action" specifies how
139 it is to be processed. Valid values are "read" (the default) or "skip"
140 (silently skip the path).
141 </P>
142 <P>
143 <b>-d</b> <i>action</i>, <b>--directories=</b><i>action</i>
144 If an input path is a directory, "action" specifies how it is to be processed.
145 Valid values are "read" (the default), "recurse" (equivalent to the <b>-r</b>
146 option), or "skip" (silently skip the path). In the default case, directories
147 are read as if they were ordinary files. In some operating systems the effect
148 of reading a directory like this is an immediate end-of-file.
149 </P>
150 <P>
151 <b>-e</b> <i>pattern</i>, <b>--regex=</b><i>pattern</i>,
152 <b>--regexp=</b><i>pattern</i> Specify a pattern to be matched. This option can
153 be used multiple times in order to specify several patterns. It can also be
154 used as a way of specifying a single pattern that starts with a hyphen. When
155 <b>-e</b> is used, no argument pattern is taken from the command line; all
156 arguments are treated as file names. There is an overall maximum of 100
157 patterns. They are applied to each line in the order in which they are defined
158 until one matches (or fails to match if <b>-v</b> is used). If <b>-f</b> is used
159 with <b>-e</b>, the command line patterns are matched first, followed by the
160 patterns from the file, independent of the order in which these options are
161 specified. Note that multiple use of <b>-e</b> is not the same as a single
162 pattern with alternatives. For example, X|Y finds the first character in a line
163 that is X or Y, whereas if the two patterns are given separately,
164 <b>pcregrep</b> finds X if it is present, even if it follows Y in the line. It
165 finds Y only if there is no X in the line. This really matters only if you are
166 using <b>-o</b> to show the portion of the line that matched.
167 </P>
168 <P>
169 <b>--exclude</b>=<i>pattern</i>
170 When <b>pcregrep</b> is searching the files in a directory as a consequence of
171 the <b>-r</b> (recursive search) option, any files whose names match the pattern
172 are excluded. The pattern is a PCRE regular expression. If a file name matches
173 both <b>--include</b> and <b>--exclude</b>, it is excluded. There is no short
174 form for this option.
175 </P>
176 <P>
177 <b>-F</b>, <b>--fixed-strings</b>
178 Interpret each pattern as a list of fixed strings, separated by newlines,
179 instead of as a regular expression. The <b>-w</b> (match as a word) and <b>-x</b>
180 (match whole line) options can be used with <b>-F</b>. They apply to each of the
181 fixed strings. A line is selected if any of the fixed strings are found in it
182 (subject to <b>-w</b> or <b>-x</b>, if present).
183 </P>
184 <P>
185 <b>-f</b> <i>filename</i>, <b>--file=</b><i>filename</i>
186 Read a number of patterns from the file, one per line, and match them against
187 each line of input. A data line is output if any of the patterns match it. The
188 filename can be given as "-" to refer to the standard input. When <b>-f</b> is
189 used, patterns specified on the command line using <b>-e</b> may also be
190 present; they are tested before the file's patterns. However, no other pattern
191 is taken from the command line; all arguments are treated as file names. There
192 is an overall maximum of 100 patterns. Trailing white space is removed from
193 each line, and blank lines are ignored. An empty file contains no patterns and
194 therefore matches nothing.
195 </P>
196 <P>
197 <b>-H</b>, <b>--with-filename</b>
198 Force the inclusion of the filename at the start of output lines when searching
199 a single file. By default, the filename is not shown in this case. For matching
200 lines, the filename is followed by a colon and a space; for context lines, a
201 hyphen separator is used. If a line number is also being output, it follows the
202 file name without a space.
203 </P>
204 <P>
205 <b>-h</b>, <b>--no-filename</b>
206 Suppress the output filenames when searching multiple files. By default,
207 filenames are shown when multiple files are searched. For matching lines, the
208 filename is followed by a colon and a space; for context lines, a hyphen
209 separator is used. If a line number is also being output, it follows the file
210 name without a space.
211 </P>
212 <P>
213 <b>--help</b>
214 Output a brief help message and exit.
215 </P>
216 <P>
217 <b>-i</b>, <b>--ignore-case</b>
218 Ignore upper/lower case distinctions during comparisons.
219 </P>
220 <P>
221 <b>--include</b>=<i>pattern</i>
222 When <b>pcregrep</b> is searching the files in a directory as a consequence of
223 the <b>-r</b> (recursive search) option, only those files whose names match the
224 pattern are included. The pattern is a PCRE regular expression. If a file name
225 matches both <b>--include</b> and <b>--exclude</b>, it is excluded. There is no
226 short form for this option.
227 </P>
228 <P>
229 <b>-L</b>, <b>--files-without-match</b>
230 Instead of outputting lines from the files, just output the names of the files
231 that do not contain any lines that would have been output. Each file name is
232 output once, on a separate line.
233 </P>
234 <P>
235 <b>-l</b>, <b>--files-with-matches</b>
236 Instead of outputting lines from the files, just output the names of the files
237 containing lines that would have been output. Each file name is output
238 once, on a separate line. Searching stops as soon as a matching line is found
239 in a file.
240 </P>
241 <P>
242 <b>--label</b>=<i>name</i>
243 This option supplies a name to be used for the standard input when file names
244 are being output. If not supplied, "(standard input)" is used. There is no
245 short form for this option.
246 </P>
247 <P>
248 <b>--locale</b>=<i>locale-name</i>
249 This option specifies a locale to be used for pattern matching. It overrides
250 the value in the <b>LC_ALL</b> or <b>LC_CTYPE</b> environment variables. If no
251 locale is specified, the PCRE library's default (usually the "C" locale) is
252 used. There is no short form for this option.
253 </P>
254 <P>
255 <b>-M</b>, <b>--multiline</b>
256 Allow patterns to match more than one line. When this option is given, patterns
257 may usefully contain literal newline characters and internal occurrences of ^
258 and $ characters. The output for any one match may consist of more than one
259 line. When this option is set, the PCRE library is called in "multiline" mode.
260 There is a limit to the number of lines that can be matched, imposed by the way
261 that <b>pcregrep</b> buffers the input file as it scans it. However,
262 <b>pcregrep</b> ensures that at least 8K characters or the rest of the document
263 (whichever is the shorter) are available for forward matching, and similarly
264 the previous 8K characters (or all the previous characters, if fewer than 8K)
265 are guaranteed to be available for lookbehind assertions.
266 </P>
267 <P>
268 <b>-n</b>, <b>--line-number</b>
269 Precede each output line by its line number in the file, followed by a colon
270 and a space for matching lines or a hyphen and a space for context lines. If
271 the filename is also being output, it precedes the line number.
272 </P>
273 <P>
274 <b>-o</b>, <b>--only-matching</b>
275 Show only the part of the line that matched a pattern. In this mode, no
276 context is shown. That is, the <b>-A</b>, <b>-B</b>, and <b>-C</b> options are
277 ignored.
278 </P>
279 <P>
280 <b>-q</b>, <b>--quiet</b>
281 Work quietly, that is, display nothing except error messages. The exit
282 status indicates whether or not any matches were found.
283 </P>
284 <P>
285 <b>-r</b>, <b>--recursive</b>
286 If any given path is a directory, recursively scan the files it contains,
287 taking note of any <b>--include</b> and <b>--exclude</b> settings. By default, a
288 directory is read as a normal file; in some operating systems this gives an
289 immediate end-of-file. This option is a shorthand for setting the <b>-d</b>
290 option to "recurse".
291 </P>
292 <P>
293 <b>-s</b>, <b>--no-messages</b>
294 Suppress error messages about non-existent or unreadable files. Such files are
295 quietly skipped. However, the return code is still 2, even if matches were
296 found in other files.
297 </P>
298 <P>
299 <b>-u</b>, <b>--utf-8</b>
300 Operate in UTF-8 mode. This option is available only if PCRE has been compiled
301 with UTF-8 support. Both patterns and subject lines must be valid strings of
302 UTF-8 characters.
303 </P>
304 <P>
305 <b>-V</b>, <b>--version</b>
306 Write the version numbers of <b>pcregrep</b> and the PCRE library that is being
307 used to the standard error stream.
308 </P>
309 <P>
310 <b>-v</b>, <b>--invert-match</b>
311 Invert the sense of the match, so that lines which do <i>not</i> match any of
312 the patterns are the ones that are found.
313 </P>
314 <P>
315 <b>-w</b>, <b>--word-regex</b>, <b>--word-regexp</b>
316 Force the patterns to match only whole words. This is equivalent to having \b
317 at the start and end of the pattern.
318 </P>
319 <P>
320 <b>-x</b>, <b>--line-regex</b>, \fP--line-regexp\fP
321 Force the patterns to be anchored (each must start matching at the beginning of
322 a line) and in addition, require them to match entire lines. This is
323 equivalent to having ^ and $ characters at the start and end of each
324 alternative branch in every pattern.
325 </P>
326 <br><a name="SEC4" href="#TOC1">ENVIRONMENT VARIABLES</a><br>
327 <P>
328 The environment variables <b>LC_ALL</b> and <b>LC_CTYPE</b> are examined, in that
329 order, for a locale. The first one that is set is used. This can be overridden
330 by the <b>--locale</b> option. If no locale is set, the PCRE library's default
331 (usually the "C" locale) is used.
332 </P>
333 <br><a name="SEC5" href="#TOC1">OPTIONS COMPATIBILITY</a><br>
334 <P>
335 The majority of short and long forms of <b>pcregrep</b>'s options are the same
336 as in the GNU <b>grep</b> program. Any long option of the form
337 <b>--xxx-regexp</b> (GNU terminology) is also available as <b>--xxx-regex</b>
338 (PCRE terminology). However, the <b>--locale</b>, <b>-M</b>, <b>--multiline</b>,
339 <b>-u</b>, and <b>--utf-8</b> options are specific to <b>pcregrep</b>.
340 </P>
341 <br><a name="SEC6" href="#TOC1">OPTIONS WITH DATA</a><br>
342 <P>
343 There are four different ways in which an option with data can be specified.
344 If a short form option is used, the data may follow immediately, or in the next
345 command line item. For example:
346 <pre>
347 -f/some/file
348 -f /some/file
349 </pre>
350 If a long form option is used, the data may appear in the same command line
351 item, separated by an equals character, or (with one exception) it may appear
352 in the next command line item. For example:
353 <pre>
354 --file=/some/file
355 --file /some/file
356 </pre>
357 Note, however, that if you want to supply a file name beginning with ~ as data
358 in a shell command, and have the shell expand ~ to a home directory, you must
359 separate the file name from the option, because the shell does not treat ~
360 specially unless it is at the start of an item.
361 </P>
362 <P>
363 The exception to the above is the <b>--colour</b> (or <b>--color</b>) option,
364 for which the data is optional. If this option does have data, it must be given
365 in the first form, using an equals character. Otherwise it will be assumed that
366 it has no data.
367 </P>
368 <br><a name="SEC7" href="#TOC1">MATCHING ERRORS</a><br>
369 <P>
370 It is possible to supply a regular expression that takes a very long time to
371 fail to match certain lines. Such patterns normally involve nested indefinite
372 repeats, for example: (a+)*\d when matched against a line of a's with no final
373 digit. The PCRE matching function has a resource limit that causes it to abort
374 in these circumstances. If this happens, <b>pcregrep</b> outputs an error
375 message and the line that caused the problem to the standard error stream. If
376 there are more than 20 such errors, <b>pcregrep</b> gives up.
377 </P>
378 <br><a name="SEC8" href="#TOC1">DIAGNOSTICS</a><br>
379 <P>
380 Exit status is 0 if any matches were found, 1 if no matches were found, and 2
381 for syntax errors and non-existent or inacessible files (even if matches were
382 found in other files) or too many matching errors. Using the <b>-s</b> option to
383 suppress error messages about inaccessble files does not affect the return
384 code.
385 </P>
386 <br><a name="SEC9" href="#TOC1">AUTHOR</a><br>
387 <P>
388 Philip Hazel
389 <br>
390 University Computing Service
391 <br>
392 Cambridge CB2 3QG, England.
393 </P>
394 <P>
395 Last updated: 23 January 2006
396 <br>
397 Copyright &copy; 1997-2006 University of Cambridge.
398 <p>
399 Return to the <a href="index.html">PCRE index page</a>.
400 </p>

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12