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