/[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 111 - (hide annotations) (download) (as text)
Thu Mar 8 16:53:09 2007 UTC (7 years, 4 months ago) by ph10
File MIME type: text/html
File size: 20052 byte(s)
Create the PrepareRelease script to process the documentation and create the 
.generic files for distribution, also to remove trailing spaces. Update a lot 
more of the build-time documentation. Arrange for PrepareRelease and its 
sub-scripts to be distributed.

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

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