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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.77  
changed lines
  Added in v.453

  ViewVC Help
Powered by ViewVC 1.1.5