/[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 91 - (hide annotations) (download) (as text)
Sat Feb 24 21:41:34 2007 UTC (7 years, 5 months ago) by nigel
File MIME type: text/html
File size: 19485 byte(s)
Load pcre-6.7 into code/trunk.

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

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12