Annotation of embedaddon/pcre/doc/html/pcregrep.html, revision 1.1.1.3

1.1       misho       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>
1.1.1.2   misho      19: <li><a name="TOC4" href="#SEC4">BINARY FILES</a>
                     20: <li><a name="TOC5" href="#SEC5">OPTIONS</a>
                     21: <li><a name="TOC6" href="#SEC6">ENVIRONMENT VARIABLES</a>
                     22: <li><a name="TOC7" href="#SEC7">NEWLINES</a>
                     23: <li><a name="TOC8" href="#SEC8">OPTIONS COMPATIBILITY</a>
                     24: <li><a name="TOC9" href="#SEC9">OPTIONS WITH DATA</a>
                     25: <li><a name="TOC10" href="#SEC10">MATCHING ERRORS</a>
                     26: <li><a name="TOC11" href="#SEC11">DIAGNOSTICS</a>
                     27: <li><a name="TOC12" href="#SEC12">SEE ALSO</a>
                     28: <li><a name="TOC13" href="#SEC13">AUTHOR</a>
                     29: <li><a name="TOC14" href="#SEC14">REVISION</a>
1.1       misho      30: </ul>
                     31: <br><a name="SEC1" href="#TOC1">SYNOPSIS</a><br>
                     32: <P>
                     33: <b>pcregrep [options] [long options] [pattern] [path1 path2 ...]</b>
                     34: </P>
                     35: <br><a name="SEC2" href="#TOC1">DESCRIPTION</a><br>
                     36: <P>
                     37: <b>pcregrep</b> searches files for character patterns, in the same way as other
                     38: grep commands do, but it uses the PCRE regular expression library to support
                     39: patterns that are compatible with the regular expressions of Perl 5. See
                     40: <a href="pcrepattern.html"><b>pcrepattern</b>(3)</a>
                     41: for a full description of syntax and semantics of the regular expressions
                     42: that PCRE supports.
                     43: </P>
                     44: <P>
                     45: Patterns, whether supplied on the command line or in a separate file, are given
                     46: without delimiters. For example:
                     47: <pre>
                     48:   pcregrep Thursday /etc/motd
                     49: </pre>
                     50: If you attempt to use delimiters (for example, by surrounding a pattern with
                     51: slashes, as is common in Perl scripts), they are interpreted as part of the
                     52: pattern. Quotes can of course be used to delimit patterns on the command line
1.1.1.3 ! misho      53: because they are interpreted by the shell, and indeed quotes are required if a
1.1       misho      54: pattern contains white space or shell metacharacters.
                     55: </P>
                     56: <P>
                     57: The first argument that follows any option settings is treated as the single
                     58: pattern to be matched when neither <b>-e</b> nor <b>-f</b> is present.
                     59: Conversely, when one or both of these options are used to specify patterns, all
                     60: arguments are treated as path names. At least one of <b>-e</b>, <b>-f</b>, or an
                     61: argument pattern must be provided.
                     62: </P>
                     63: <P>
                     64: If no files are specified, <b>pcregrep</b> reads the standard input. The
                     65: standard input can also be referenced by a name consisting of a single hyphen.
                     66: For example:
                     67: <pre>
                     68:   pcregrep some-pattern /file1 - /file3
                     69: </pre>
                     70: By default, each line that matches a pattern is copied to the standard
                     71: output, and if there is more than one file, the file name is output at the
                     72: start of each line, followed by a colon. However, there are options that can
                     73: change how <b>pcregrep</b> behaves. In particular, the <b>-M</b> option makes it
                     74: possible to search for patterns that span line boundaries. What defines a line
                     75: boundary is controlled by the <b>-N</b> (<b>--newline</b>) option.
                     76: </P>
                     77: <P>
                     78: The amount of memory used for buffering files that are being scanned is
                     79: controlled by a parameter that can be set by the <b>--buffer-size</b> option.
                     80: The default value for this parameter is specified when <b>pcregrep</b> is built,
                     81: with the default default being 20K. A block of memory three times this size is
                     82: used (to allow for buffering "before" and "after" lines). An error occurs if a
                     83: line overflows the buffer.
                     84: </P>
                     85: <P>
1.1.1.3 ! misho      86: Patterns can be no longer than 8K or BUFSIZ bytes, whichever is the greater.
        !            87: BUFSIZ is defined in <b>&#60;stdio.h&#62;</b>. When there is more than one pattern
        !            88: (specified by the use of <b>-e</b> and/or <b>-f</b>), each pattern is applied to
        !            89: each line in the order in which they are defined, except that all the <b>-e</b>
        !            90: patterns are tried before the <b>-f</b> patterns.
        !            91: </P>
        !            92: <P>
        !            93: By default, as soon as one pattern matches a line, no further patterns are
        !            94: considered. However, if <b>--colour</b> (or <b>--color</b>) is used to colour the
        !            95: matching substrings, or if <b>--only-matching</b>, <b>--file-offsets</b>, or
        !            96: <b>--line-offsets</b> is used to output only the part of the line that matched
        !            97: (either shown literally, or as an offset), scanning resumes immediately
        !            98: following the match, so that further matches on the same line can be found. If
        !            99: there are multiple patterns, they are all tried on the remainder of the line,
        !           100: but patterns that follow the one that matched are not tried on the earlier part
        !           101: of the line.
        !           102: </P>
        !           103: <P>
        !           104: This behaviour means that the order in which multiple patterns are specified
        !           105: can affect the output when one of the above options is used. This is no longer
        !           106: the same behaviour as GNU grep, which now manages to display earlier matches
        !           107: for later patterns (as long as there is no overlap).
1.1       misho     108: </P>
                    109: <P>
                    110: Patterns that can match an empty string are accepted, but empty string
                    111: matches are never recognized. An example is the pattern "(super)?(man)?", in
                    112: which all components are optional. This pattern finds all occurrences of both
                    113: "super" and "man"; the output differs from matching with "super|man" when only
                    114: the matching substrings are being shown.
                    115: </P>
                    116: <P>
                    117: If the <b>LC_ALL</b> or <b>LC_CTYPE</b> environment variable is set,
                    118: <b>pcregrep</b> uses the value to set a locale when calling the PCRE library.
                    119: The <b>--locale</b> option can be used to override this.
                    120: </P>
                    121: <br><a name="SEC3" href="#TOC1">SUPPORT FOR COMPRESSED FILES</a><br>
                    122: <P>
                    123: It is possible to compile <b>pcregrep</b> so that it uses <b>libz</b> or
                    124: <b>libbz2</b> to read files whose names end in <b>.gz</b> or <b>.bz2</b>,
                    125: respectively. You can find out whether your binary has support for one or both
                    126: of these file types by running it with the <b>--help</b> option. If the
                    127: appropriate support is not present, files are treated as plain text. The
                    128: standard input is always so treated.
                    129: </P>
1.1.1.2   misho     130: <br><a name="SEC4" href="#TOC1">BINARY FILES</a><br>
                    131: <P>
                    132: By default, a file that contains a binary zero byte within the first 1024 bytes
                    133: is identified as a binary file, and is processed specially. (GNU grep also
                    134: identifies binary files in this manner.) See the <b>--binary-files</b> option
                    135: for a means of changing the way binary files are handled.
                    136: </P>
                    137: <br><a name="SEC5" href="#TOC1">OPTIONS</a><br>
1.1       misho     138: <P>
                    139: The order in which some of the options appear can affect the output. For
                    140: example, both the <b>-h</b> and <b>-l</b> options affect the printing of file
                    141: names. Whichever comes later in the command line will be the one that takes
1.1.1.3 ! misho     142: effect. Similarly, except where noted below, if an option is given twice, the
        !           143: later setting is used. Numerical values for options may be followed by K or M,
        !           144: to signify multiplication by 1024 or 1024*1024 respectively.
1.1       misho     145: </P>
                    146: <P>
                    147: <b>--</b>
                    148: This terminates the list of options. It is useful if the next item on the
                    149: command line starts with a hyphen but is not an option. This allows for the
                    150: processing of patterns and filenames that start with hyphens.
                    151: </P>
                    152: <P>
                    153: <b>-A</b> <i>number</i>, <b>--after-context=</b><i>number</i>
                    154: Output <i>number</i> lines of context after each matching line. If filenames
                    155: and/or line numbers are being output, a hyphen separator is used instead of a
                    156: colon for the context lines. A line containing "--" is output between each
                    157: group of lines, unless they are in fact contiguous in the input file. The value
                    158: of <i>number</i> is expected to be relatively small. However, <b>pcregrep</b>
                    159: guarantees to have up to 8K of following text available for context output.
                    160: </P>
                    161: <P>
1.1.1.2   misho     162: <b>-a</b>, <b>--text</b>
                    163: Treat binary files as text. This is equivalent to
                    164: <b>--binary-files</b>=<i>text</i>.
                    165: </P>
                    166: <P>
1.1       misho     167: <b>-B</b> <i>number</i>, <b>--before-context=</b><i>number</i>
                    168: Output <i>number</i> lines of context before each matching line. If filenames
                    169: and/or line numbers are being output, a hyphen separator is used instead of a
                    170: colon for the context lines. A line containing "--" is output between each
                    171: group of lines, unless they are in fact contiguous in the input file. The value
                    172: of <i>number</i> is expected to be relatively small. However, <b>pcregrep</b>
                    173: guarantees to have up to 8K of preceding text available for context output.
                    174: </P>
                    175: <P>
1.1.1.2   misho     176: <b>--binary-files=</b><i>word</i>
                    177: Specify how binary files are to be processed. If the word is "binary" (the
                    178: default), pattern matching is performed on binary files, but the only output is
                    179: "Binary file &#60;name&#62; matches" when a match succeeds. If the word is "text",
                    180: which is equivalent to the <b>-a</b> or <b>--text</b> option, binary files are
                    181: processed in the same way as any other file. In this case, when a match
                    182: succeeds, the output may be binary garbage, which can have nasty effects if
                    183: sent to a terminal. If the word is "without-match", which is equivalent to the
                    184: <b>-I</b> option, binary files are not processed at all; they are assumed not to
                    185: be of interest.
                    186: </P>
                    187: <P>
1.1       misho     188: <b>--buffer-size=</b><i>number</i>
                    189: Set the parameter that controls how much memory is used for buffering files
                    190: that are being scanned.
                    191: </P>
                    192: <P>
                    193: <b>-C</b> <i>number</i>, <b>--context=</b><i>number</i>
                    194: Output <i>number</i> lines of context both before and after each matching line.
                    195: This is equivalent to setting both <b>-A</b> and <b>-B</b> to the same value.
                    196: </P>
                    197: <P>
                    198: <b>-c</b>, <b>--count</b>
                    199: Do not output individual lines from the files that are being scanned; instead
                    200: output the number of lines that would otherwise have been shown. If no lines
                    201: are selected, the number zero is output. If several files are are being
                    202: scanned, a count is output for each of them. However, if the
                    203: <b>--files-with-matches</b> option is also used, only those files whose counts
                    204: are greater than zero are listed. When <b>-c</b> is used, the <b>-A</b>,
                    205: <b>-B</b>, and <b>-C</b> options are ignored.
                    206: </P>
                    207: <P>
                    208: <b>--colour</b>, <b>--color</b>
                    209: If this option is given without any data, it is equivalent to "--colour=auto".
                    210: If data is required, it must be given in the same shell item, separated by an
                    211: equals sign.
                    212: </P>
                    213: <P>
                    214: <b>--colour=</b><i>value</i>, <b>--color=</b><i>value</i>
                    215: This option specifies under what circumstances the parts of a line that matched
                    216: a pattern should be coloured in the output. By default, the output is not
                    217: coloured. The value (which is optional, see above) may be "never", "always", or
                    218: "auto". In the latter case, colouring happens only if the standard output is
                    219: connected to a terminal. More resources are used when colouring is enabled,
                    220: because <b>pcregrep</b> has to search for all possible matches in a line, not
                    221: just one, in order to colour them all.
                    222: <br>
                    223: <br>
                    224: The colour that is used can be specified by setting the environment variable
                    225: PCREGREP_COLOUR or PCREGREP_COLOR. The value of this variable should be a
                    226: string of two numbers, separated by a semicolon. They are copied directly into
                    227: the control string for setting colour on a terminal, so it is your
                    228: responsibility to ensure that they make sense. If neither of the environment
                    229: variables is set, the default is "1;31", which gives red.
                    230: </P>
                    231: <P>
                    232: <b>-D</b> <i>action</i>, <b>--devices=</b><i>action</i>
                    233: If an input path is not a regular file or a directory, "action" specifies how
                    234: it is to be processed. Valid values are "read" (the default) or "skip"
                    235: (silently skip the path).
                    236: </P>
                    237: <P>
                    238: <b>-d</b> <i>action</i>, <b>--directories=</b><i>action</i>
                    239: If an input path is a directory, "action" specifies how it is to be processed.
1.1.1.3 ! misho     240: Valid values are "read" (the default in non-Windows environments, for
        !           241: compatibility with GNU grep), "recurse" (equivalent to the <b>-r</b> option), or
        !           242: "skip" (silently skip the path, the default in Windows environments). In the
        !           243: "read" case, directories are read as if they were ordinary files. In some
        !           244: operating systems the effect of reading a directory like this is an immediate
        !           245: end-of-file; in others it may provoke an error.
1.1       misho     246: </P>
                    247: <P>
                    248: <b>-e</b> <i>pattern</i>, <b>--regex=</b><i>pattern</i>, <b>--regexp=</b><i>pattern</i>
                    249: Specify a pattern to be matched. This option can be used multiple times in
                    250: order to specify several patterns. It can also be used as a way of specifying a
                    251: single pattern that starts with a hyphen. When <b>-e</b> is used, no argument
                    252: pattern is taken from the command line; all arguments are treated as file
1.1.1.3 ! misho     253: names. There is no limit to the number of patterns. They are applied to each
        !           254: line in the order in which they are defined until one matches.
        !           255: <br>
        !           256: <br>
        !           257: If <b>-f</b> is used with <b>-e</b>, the command line patterns are matched first,
        !           258: followed by the patterns from the file(s), independent of the order in which
        !           259: these options are specified. Note that multiple use of <b>-e</b> is not the same
        !           260: as a single pattern with alternatives. For example, X|Y finds the first
        !           261: character in a line that is X or Y, whereas if the two patterns are given
        !           262: separately, with X first, <b>pcregrep</b> finds X if it is present, even if it
        !           263: follows Y in the line. It finds Y only if there is no X in the line. This
        !           264: matters only if you are using <b>-o</b> or <b>--colo(u)r</b> to show the part(s)
        !           265: of the line that matched.
1.1       misho     266: </P>
                    267: <P>
                    268: <b>--exclude</b>=<i>pattern</i>
1.1.1.3 ! misho     269: Files (but not directories) whose names match the pattern are skipped without
        !           270: being processed. This applies to all files, whether listed on the command line,
        !           271: obtained from <b>--file-list</b>, or by scanning a directory. The pattern is a
        !           272: PCRE regular expression, and is matched against the final component of the file
        !           273: name, not the entire path. The <b>-F</b>, <b>-w</b>, and <b>-x</b> options do not
        !           274: apply to this pattern. The option may be given any number of times in order to
        !           275: specify multiple patterns. If a file name matches both an <b>--include</b>
        !           276: and an <b>--exclude</b> pattern, it is excluded. There is no short form for this
        !           277: option.
        !           278: </P>
        !           279: <P>
        !           280: <b>--exclude-from=</b><i>filename</i>
        !           281: Treat each non-empty line of the file as the data for an <b>--exclude</b>
        !           282: option. What constitutes a newline when reading the file is the operating
        !           283: system's default. The <b>--newline</b> option has no effect on this option. This
        !           284: option may be given more than once in order to specify a number of files to
        !           285: read.
1.1       misho     286: </P>
                    287: <P>
                    288: <b>--exclude-dir</b>=<i>pattern</i>
1.1.1.3 ! misho     289: Directories whose names match the pattern are skipped without being processed,
        !           290: whatever the setting of the <b>--recursive</b> option. This applies to all
        !           291: directories, whether listed on the command line, obtained from
        !           292: <b>--file-list</b>, or by scanning a parent directory. The pattern is a PCRE
        !           293: regular expression, and is matched against the final component of the directory
        !           294: name, not the entire path. The <b>-F</b>, <b>-w</b>, and <b>-x</b> options do not
        !           295: apply to this pattern. The option may be given any number of times in order to
        !           296: specify more than one pattern. If a directory matches both <b>--include-dir</b>
        !           297: and <b>--exclude-dir</b>, it is excluded. There is no short form for this
        !           298: option.
1.1       misho     299: </P>
                    300: <P>
                    301: <b>-F</b>, <b>--fixed-strings</b>
1.1.1.3 ! misho     302: Interpret each data-matching pattern as a list of fixed strings, separated by
        !           303: newlines, instead of as a regular expression. What constitutes a newline for
        !           304: this purpose is controlled by the <b>--newline</b> option. The <b>-w</b> (match
        !           305: as a word) and <b>-x</b> (match whole line) options can be used with <b>-F</b>.
        !           306: They apply to each of the fixed strings. A line is selected if any of the fixed
        !           307: strings are found in it (subject to <b>-w</b> or <b>-x</b>, if present). This
        !           308: option applies only to the patterns that are matched against the contents of
        !           309: files; it does not apply to patterns specified by any of the <b>--include</b> or
        !           310: <b>--exclude</b> options.
1.1       misho     311: </P>
                    312: <P>
                    313: <b>-f</b> <i>filename</i>, <b>--file=</b><i>filename</i>
1.1.1.3 ! misho     314: Read patterns from the file, one per line, and match them against
        !           315: each line of input. What constitutes a newline when reading the file is the
        !           316: operating system's default. The <b>--newline</b> option has no effect on this
        !           317: option. Trailing white space is removed from each line, and blank lines are
        !           318: ignored. An empty file contains no patterns and therefore matches nothing. See
        !           319: also the comments about multiple patterns versus a single pattern with
        !           320: alternatives in the description of <b>-e</b> above.
        !           321: <br>
        !           322: <br>
        !           323: If this option is given more than once, all the specified files are
        !           324: read. A data line is output if any of the patterns match it. A filename can
        !           325: be given as "-" to refer to the standard input. When <b>-f</b> is used, patterns
        !           326: specified on the command line using <b>-e</b> may also be present; they are
        !           327: tested before the file's patterns. However, no other pattern is taken from the
        !           328: command line; all arguments are treated as the names of paths to be searched.
1.1.1.2   misho     329: </P>
                    330: <P>
                    331: <b>--file-list</b>=<i>filename</i>
1.1.1.3 ! misho     332: Read a list of files and/or directories that are to be scanned from the given
        !           333: file, one per line. Trailing white space is removed from each line, and blank
        !           334: lines are ignored. These paths are processed before any that are listed on the
        !           335: command line. The filename can be given as "-" to refer to the standard input.
        !           336: If <b>--file</b> and <b>--file-list</b> are both specified as "-", patterns are
        !           337: read first. This is useful only when the standard input is a terminal, from
        !           338: which further lines (the list of files) can be read after an end-of-file
        !           339: indication. If this option is given more than once, all the specified files are
        !           340: read.
1.1       misho     341: </P>
                    342: <P>
                    343: <b>--file-offsets</b>
                    344: Instead of showing lines or parts of lines that match, show each match as an
                    345: offset from the start of the file and a length, separated by a comma. In this
                    346: mode, no context is shown. That is, the <b>-A</b>, <b>-B</b>, and <b>-C</b>
                    347: options are ignored. If there is more than one match in a line, each of them is
                    348: shown separately. This option is mutually exclusive with <b>--line-offsets</b>
                    349: and <b>--only-matching</b>.
                    350: </P>
                    351: <P>
                    352: <b>-H</b>, <b>--with-filename</b>
                    353: Force the inclusion of the filename at the start of output lines when searching
                    354: a single file. By default, the filename is not shown in this case. For matching
                    355: lines, the filename is followed by a colon; for context lines, a hyphen
                    356: separator is used. If a line number is also being output, it follows the file
                    357: name.
                    358: </P>
                    359: <P>
                    360: <b>-h</b>, <b>--no-filename</b>
                    361: Suppress the output filenames when searching multiple files. By default,
                    362: filenames are shown when multiple files are searched. For matching lines, the
                    363: filename is followed by a colon; for context lines, a hyphen separator is used.
                    364: If a line number is also being output, it follows the file name.
                    365: </P>
                    366: <P>
                    367: <b>--help</b>
                    368: Output a help message, giving brief details of the command options and file
1.1.1.3 ! misho     369: type support, and then exit. Anything else on the command line is
        !           370: ignored.
1.1       misho     371: </P>
                    372: <P>
1.1.1.2   misho     373: <b>-I</b>
                    374: Treat binary files as never matching. This is equivalent to
                    375: <b>--binary-files</b>=<i>without-match</i>.
                    376: </P>
                    377: <P>
1.1       misho     378: <b>-i</b>, <b>--ignore-case</b>
                    379: Ignore upper/lower case distinctions during comparisons.
                    380: </P>
                    381: <P>
                    382: <b>--include</b>=<i>pattern</i>
1.1.1.3 ! misho     383: If any <b>--include</b> patterns are specified, the only files that are
        !           384: processed are those that match one of the patterns (and do not match an
        !           385: <b>--exclude</b> pattern). This option does not affect directories, but it
        !           386: applies to all files, whether listed on the command line, obtained from
        !           387: <b>--file-list</b>, or by scanning a directory. The pattern is a PCRE regular
        !           388: expression, and is matched against the final component of the file name, not
        !           389: the entire path. The <b>-F</b>, <b>-w</b>, and <b>-x</b> options do not apply to
        !           390: this pattern. The option may be given any number of times. If a file name
        !           391: matches both an <b>--include</b> and an <b>--exclude</b> pattern, it is excluded.
        !           392: There is no short form for this option.
        !           393: </P>
        !           394: <P>
        !           395: <b>--include-from=</b><i>filename</i>
        !           396: Treat each non-empty line of the file as the data for an <b>--include</b>
        !           397: option. What constitutes a newline for this purpose is the operating system's
        !           398: default. The <b>--newline</b> option has no effect on this option. This option
        !           399: may be given any number of times; all the files are read.
1.1       misho     400: </P>
                    401: <P>
                    402: <b>--include-dir</b>=<i>pattern</i>
1.1.1.3 ! misho     403: If any <b>--include-dir</b> patterns are specified, the only directories that
        !           404: are processed are those that match one of the patterns (and do not match an
        !           405: <b>--exclude-dir</b> pattern). This applies to all directories, whether listed
        !           406: on the command line, obtained from <b>--file-list</b>, or by scanning a parent
        !           407: directory. The pattern is a PCRE regular expression, and is matched against the
        !           408: final component of the directory name, not the entire path. The <b>-F</b>,
        !           409: <b>-w</b>, and <b>-x</b> options do not apply to this pattern. The option may be
        !           410: given any number of times. If a directory matches both <b>--include-dir</b> and
        !           411: <b>--exclude-dir</b>, it is excluded. There is no short form for this option.
1.1       misho     412: </P>
                    413: <P>
                    414: <b>-L</b>, <b>--files-without-match</b>
                    415: Instead of outputting lines from the files, just output the names of the files
                    416: that do not contain any lines that would have been output. Each file name is
                    417: output once, on a separate line.
                    418: </P>
                    419: <P>
                    420: <b>-l</b>, <b>--files-with-matches</b>
                    421: Instead of outputting lines from the files, just output the names of the files
                    422: containing lines that would have been output. Each file name is output
                    423: once, on a separate line. Searching normally stops as soon as a matching line
                    424: is found in a file. However, if the <b>-c</b> (count) option is also used,
                    425: matching continues in order to obtain the correct count, and those files that
                    426: have at least one match are listed along with their counts. Using this option
                    427: with <b>-c</b> is a way of suppressing the listing of files with no matches.
                    428: </P>
                    429: <P>
                    430: <b>--label</b>=<i>name</i>
                    431: This option supplies a name to be used for the standard input when file names
                    432: are being output. If not supplied, "(standard input)" is used. There is no
                    433: short form for this option.
                    434: </P>
                    435: <P>
                    436: <b>--line-buffered</b>
                    437: When this option is given, input is read and processed line by line, and the
                    438: output is flushed after each write. By default, input is read in large chunks,
                    439: unless <b>pcregrep</b> can determine that it is reading from a terminal (which
1.1.1.3 ! misho     440: is currently possible only in Unix-like environments). Output to terminal is
1.1       misho     441: normally automatically flushed by the operating system. This option can be
                    442: useful when the input or output is attached to a pipe and you do not want
                    443: <b>pcregrep</b> to buffer up large amounts of data. However, its use will affect
                    444: performance, and the <b>-M</b> (multiline) option ceases to work.
                    445: </P>
                    446: <P>
                    447: <b>--line-offsets</b>
                    448: Instead of showing lines or parts of lines that match, show each match as a
                    449: line number, the offset from the start of the line, and a length. The line
                    450: number is terminated by a colon (as usual; see the <b>-n</b> option), and the
                    451: offset and length are separated by a comma. In this mode, no context is shown.
                    452: That is, the <b>-A</b>, <b>-B</b>, and <b>-C</b> options are ignored. If there is
                    453: more than one match in a line, each of them is shown separately. This option is
                    454: mutually exclusive with <b>--file-offsets</b> and <b>--only-matching</b>.
                    455: </P>
                    456: <P>
                    457: <b>--locale</b>=<i>locale-name</i>
                    458: This option specifies a locale to be used for pattern matching. It overrides
                    459: the value in the <b>LC_ALL</b> or <b>LC_CTYPE</b> environment variables. If no
                    460: locale is specified, the PCRE library's default (usually the "C" locale) is
                    461: used. There is no short form for this option.
                    462: </P>
                    463: <P>
                    464: <b>--match-limit</b>=<i>number</i>
                    465: Processing some regular expression patterns can require a very large amount of
                    466: memory, leading in some cases to a program crash if not enough is available.
                    467: Other patterns may take a very long time to search for all possible matching
                    468: strings. The <b>pcre_exec()</b> function that is called by <b>pcregrep</b> to do
                    469: the matching has two parameters that can limit the resources that it uses.
                    470: <br>
                    471: <br>
                    472: The <b>--match-limit</b> option provides a means of limiting resource usage
                    473: when processing patterns that are not going to match, but which have a very
                    474: large number of possibilities in their search trees. The classic example is a
                    475: pattern that uses nested unlimited repeats. Internally, PCRE uses a function
                    476: called <b>match()</b> which it calls repeatedly (sometimes recursively). The
                    477: limit set by <b>--match-limit</b> is imposed on the number of times this
                    478: function is called during a match, which has the effect of limiting the amount
                    479: of backtracking that can take place.
                    480: <br>
                    481: <br>
                    482: The <b>--recursion-limit</b> option is similar to <b>--match-limit</b>, but
                    483: instead of limiting the total number of times that <b>match()</b> is called, it
                    484: limits the depth of recursive calls, which in turn limits the amount of memory
                    485: that can be used. The recursion depth is a smaller number than the total number
                    486: of calls, because not all calls to <b>match()</b> are recursive. This limit is
                    487: of use only if it is set smaller than <b>--match-limit</b>.
                    488: <br>
                    489: <br>
                    490: There are no short forms for these options. The default settings are specified
                    491: when the PCRE library is compiled, with the default default being 10 million.
                    492: </P>
                    493: <P>
                    494: <b>-M</b>, <b>--multiline</b>
                    495: Allow patterns to match more than one line. When this option is given, patterns
                    496: may usefully contain literal newline characters and internal occurrences of ^
                    497: and $ characters. The output for a successful match may consist of more than
                    498: one line, the last of which is the one in which the match ended. If the matched
                    499: string ends with a newline sequence the output ends at the end of that line.
                    500: <br>
                    501: <br>
                    502: When this option is set, the PCRE library is called in "multiline" mode.
                    503: There is a limit to the number of lines that can be matched, imposed by the way
                    504: that <b>pcregrep</b> buffers the input file as it scans it. However,
                    505: <b>pcregrep</b> ensures that at least 8K characters or the rest of the document
                    506: (whichever is the shorter) are available for forward matching, and similarly
                    507: the previous 8K characters (or all the previous characters, if fewer than 8K)
                    508: are guaranteed to be available for lookbehind assertions. This option does not
                    509: work when input is read line by line (see \fP--line-buffered\fP.)
                    510: </P>
                    511: <P>
                    512: <b>-N</b> <i>newline-type</i>, <b>--newline</b>=<i>newline-type</i>
                    513: The PCRE library supports five different conventions for indicating
                    514: the ends of lines. They are the single-character sequences CR (carriage return)
                    515: and LF (linefeed), the two-character sequence CRLF, an "anycrlf" convention,
                    516: which recognizes any of the preceding three types, and an "any" convention, in
                    517: which any Unicode line ending sequence is assumed to end a line. The Unicode
                    518: sequences are the three just mentioned, plus VT (vertical tab, U+000B), FF
                    519: (form feed, U+000C), NEL (next line, U+0085), LS (line separator, U+2028), and
                    520: PS (paragraph separator, U+2029).
                    521: <br>
                    522: <br>
                    523: When the PCRE library is built, a default line-ending sequence is specified.
                    524: This is normally the standard sequence for the operating system. Unless
                    525: otherwise specified by this option, <b>pcregrep</b> uses the library's default.
                    526: The possible values for this option are CR, LF, CRLF, ANYCRLF, or ANY. This
1.1.1.3 ! misho     527: makes it possible to use <b>pcregrep</b> to scan files that have come from other
1.1       misho     528: environments without having to modify their line endings. If the data that is
                    529: being scanned does not agree with the convention set by this option,
1.1.1.3 ! misho     530: <b>pcregrep</b> may behave in strange ways. Note that this option does not
        !           531: apply to files specified by the <b>-f</b>, <b>--exclude-from</b>, or
        !           532: <b>--include-from</b> options, which are expected to use the operating system's
        !           533: standard newline sequence.
1.1       misho     534: </P>
                    535: <P>
                    536: <b>-n</b>, <b>--line-number</b>
                    537: Precede each output line by its line number in the file, followed by a colon
                    538: for matching lines or a hyphen for context lines. If the filename is also being
                    539: output, it precedes the line number. This option is forced if
                    540: <b>--line-offsets</b> is used.
                    541: </P>
                    542: <P>
                    543: <b>--no-jit</b>
                    544: If the PCRE library is built with support for just-in-time compiling (which
                    545: speeds up matching), <b>pcregrep</b> automatically makes use of this, unless it
                    546: was explicitly disabled at build time. This option can be used to disable the
                    547: use of JIT at run time. It is provided for testing and working round problems.
                    548: It should never be needed in normal use.
                    549: </P>
                    550: <P>
                    551: <b>-o</b>, <b>--only-matching</b>
                    552: Show only the part of the line that matched a pattern instead of the whole
                    553: line. In this mode, no context is shown. That is, the <b>-A</b>, <b>-B</b>, and
                    554: <b>-C</b> options are ignored. If there is more than one match in a line, each
                    555: of them is shown separately. If <b>-o</b> is combined with <b>-v</b> (invert the
                    556: sense of the match to find non-matching lines), no output is generated, but the
                    557: return code is set appropriately. If the matched portion of the line is empty,
                    558: nothing is output unless the file name or line number are being printed, in
                    559: which case they are shown on an otherwise empty line. This option is mutually
                    560: exclusive with <b>--file-offsets</b> and <b>--line-offsets</b>.
                    561: </P>
                    562: <P>
                    563: <b>-o</b><i>number</i>, <b>--only-matching</b>=<i>number</i>
                    564: Show only the part of the line that matched the capturing parentheses of the
1.1.1.3 ! misho     565: given number. Up to 32 capturing parentheses are supported, and -o0 is
        !           566: equivalent to <b>-o</b> without a number. Because these options can be given
        !           567: without an argument (see above), if an argument is present, it must be given in
        !           568: the same shell item, for example, -o3 or --only-matching=2. The comments given
        !           569: for the non-argument case above also apply to this case. If the specified
        !           570: capturing parentheses do not exist in the pattern, or were not set in the
        !           571: match, nothing is output unless the file name or line number are being printed.
        !           572: <br>
        !           573: <br>
        !           574: If this option is given multiple times, multiple substrings are output, in the
        !           575: order the options are given. For example, -o3 -o1 -o3 causes the substrings
        !           576: matched by capturing parentheses 3 and 1 and then 3 again to be output. By
        !           577: default, there is no separator (but see the next option).
        !           578: </P>
        !           579: <P>
        !           580: <b>--om-separator</b>=<i>text</i>
        !           581: Specify a separating string for multiple occurrences of <b>-o</b>. The default
        !           582: is an empty string. Separating strings are never coloured.
1.1       misho     583: </P>
                    584: <P>
                    585: <b>-q</b>, <b>--quiet</b>
                    586: Work quietly, that is, display nothing except error messages. The exit
                    587: status indicates whether or not any matches were found.
                    588: </P>
                    589: <P>
                    590: <b>-r</b>, <b>--recursive</b>
                    591: If any given path is a directory, recursively scan the files it contains,
                    592: taking note of any <b>--include</b> and <b>--exclude</b> settings. By default, a
                    593: directory is read as a normal file; in some operating systems this gives an
                    594: immediate end-of-file. This option is a shorthand for setting the <b>-d</b>
                    595: option to "recurse".
                    596: </P>
                    597: <P>
                    598: <b>--recursion-limit</b>=<i>number</i>
                    599: See <b>--match-limit</b> above.
                    600: </P>
                    601: <P>
                    602: <b>-s</b>, <b>--no-messages</b>
                    603: Suppress error messages about non-existent or unreadable files. Such files are
                    604: quietly skipped. However, the return code is still 2, even if matches were
                    605: found in other files.
                    606: </P>
                    607: <P>
                    608: <b>-u</b>, <b>--utf-8</b>
                    609: Operate in UTF-8 mode. This option is available only if PCRE has been compiled
1.1.1.3 ! misho     610: with UTF-8 support. All patterns (including those for any <b>--exclude</b> and
        !           611: <b>--include</b> options) and all subject lines that are scanned must be valid
        !           612: strings of UTF-8 characters.
1.1       misho     613: </P>
                    614: <P>
                    615: <b>-V</b>, <b>--version</b>
1.1.1.3 ! misho     616: Write the version numbers of <b>pcregrep</b> and the PCRE library to the
        !           617: standard output and then exit. Anything else on the command line is
        !           618: ignored.
1.1       misho     619: </P>
                    620: <P>
                    621: <b>-v</b>, <b>--invert-match</b>
                    622: Invert the sense of the match, so that lines which do <i>not</i> match any of
                    623: the patterns are the ones that are found.
                    624: </P>
                    625: <P>
                    626: <b>-w</b>, <b>--word-regex</b>, <b>--word-regexp</b>
                    627: Force the patterns to match only whole words. This is equivalent to having \b
1.1.1.3 ! misho     628: at the start and end of the pattern. This option applies only to the patterns
        !           629: that are matched against the contents of files; it does not apply to patterns
        !           630: specified by any of the <b>--include</b> or <b>--exclude</b> options.
1.1       misho     631: </P>
                    632: <P>
                    633: <b>-x</b>, <b>--line-regex</b>, <b>--line-regexp</b>
                    634: Force the patterns to be anchored (each must start matching at the beginning of
1.1.1.3 ! misho     635: a line) and in addition, require them to match entire lines. This is equivalent
        !           636: to having ^ and $ characters at the start and end of each alternative branch in
        !           637: every pattern. This option applies only to the patterns that are matched
        !           638: against the contents of files; it does not apply to patterns specified by any
        !           639: of the <b>--include</b> or <b>--exclude</b> options.
1.1       misho     640: </P>
1.1.1.2   misho     641: <br><a name="SEC6" href="#TOC1">ENVIRONMENT VARIABLES</a><br>
1.1       misho     642: <P>
                    643: The environment variables <b>LC_ALL</b> and <b>LC_CTYPE</b> are examined, in that
                    644: order, for a locale. The first one that is set is used. This can be overridden
                    645: by the <b>--locale</b> option. If no locale is set, the PCRE library's default
                    646: (usually the "C" locale) is used.
                    647: </P>
1.1.1.2   misho     648: <br><a name="SEC7" href="#TOC1">NEWLINES</a><br>
1.1       misho     649: <P>
                    650: The <b>-N</b> (<b>--newline</b>) option allows <b>pcregrep</b> to scan files with
1.1.1.3 ! misho     651: different newline conventions from the default. Any parts of the input files
        !           652: that are written to the standard output are copied identically, with whatever
        !           653: newline sequences they have in the input. However, the setting of this option
        !           654: does not affect the interpretation of files specified by the <b>-f</b>,
        !           655: <b>--exclude-from</b>, or <b>--include-from</b> options, which are assumed to use
        !           656: the operating system's standard newline sequence, nor does it affect the way in
        !           657: which <b>pcregrep</b> writes informational messages to the standard error and
        !           658: output streams. For these it uses the string "\n" to indicate newlines,
        !           659: relying on the C I/O library to convert this to an appropriate sequence.
1.1       misho     660: </P>
1.1.1.2   misho     661: <br><a name="SEC8" href="#TOC1">OPTIONS COMPATIBILITY</a><br>
1.1       misho     662: <P>
                    663: Many of the short and long forms of <b>pcregrep</b>'s options are the same
1.1.1.2   misho     664: as in the GNU <b>grep</b> program. Any long option of the form
1.1       misho     665: <b>--xxx-regexp</b> (GNU terminology) is also available as <b>--xxx-regex</b>
1.1.1.2   misho     666: (PCRE terminology). However, the <b>--file-list</b>, <b>--file-offsets</b>,
                    667: <b>--include-dir</b>, <b>--line-offsets</b>, <b>--locale</b>, <b>--match-limit</b>,
1.1.1.3 ! misho     668: <b>-M</b>, <b>--multiline</b>, <b>-N</b>, <b>--newline</b>, <b>--om-separator</b>,
1.1.1.2   misho     669: <b>--recursion-limit</b>, <b>-u</b>, and <b>--utf-8</b> options are specific to
                    670: <b>pcregrep</b>, as is the use of the <b>--only-matching</b> option with a
                    671: capturing parentheses number.
1.1       misho     672: </P>
                    673: <P>
                    674: Although most of the common options work the same way, a few are different in
                    675: <b>pcregrep</b>. For example, the <b>--include</b> option's argument is a glob
                    676: for GNU <b>grep</b>, but a regular expression for <b>pcregrep</b>. If both the
                    677: <b>-c</b> and <b>-l</b> options are given, GNU grep lists only file names,
                    678: without counts, but <b>pcregrep</b> gives the counts.
                    679: </P>
1.1.1.2   misho     680: <br><a name="SEC9" href="#TOC1">OPTIONS WITH DATA</a><br>
1.1       misho     681: <P>
                    682: There are four different ways in which an option with data can be specified.
                    683: If a short form option is used, the data may follow immediately, or (with one
                    684: exception) in the next command line item. For example:
                    685: <pre>
                    686:   -f/some/file
                    687:   -f /some/file
                    688: </pre>
                    689: The exception is the <b>-o</b> option, which may appear with or without data.
                    690: Because of this, if data is present, it must follow immediately in the same
                    691: item, for example -o3.
                    692: </P>
                    693: <P>
                    694: If a long form option is used, the data may appear in the same command line
                    695: item, separated by an equals character, or (with two exceptions) it may appear
                    696: in the next command line item. For example:
                    697: <pre>
                    698:   --file=/some/file
                    699:   --file /some/file
                    700: </pre>
                    701: Note, however, that if you want to supply a file name beginning with ~ as data
                    702: in a shell command, and have the shell expand ~ to a home directory, you must
                    703: separate the file name from the option, because the shell does not treat ~
                    704: specially unless it is at the start of an item.
                    705: </P>
                    706: <P>
                    707: The exceptions to the above are the <b>--colour</b> (or <b>--color</b>) and
                    708: <b>--only-matching</b> options, for which the data is optional. If one of these
                    709: options does have data, it must be given in the first form, using an equals
                    710: character. Otherwise <b>pcregrep</b> will assume that it has no data.
                    711: </P>
1.1.1.2   misho     712: <br><a name="SEC10" href="#TOC1">MATCHING ERRORS</a><br>
1.1       misho     713: <P>
                    714: It is possible to supply a regular expression that takes a very long time to
                    715: fail to match certain lines. Such patterns normally involve nested indefinite
                    716: repeats, for example: (a+)*\d when matched against a line of a's with no final
                    717: digit. The PCRE matching function has a resource limit that causes it to abort
                    718: in these circumstances. If this happens, <b>pcregrep</b> outputs an error
                    719: message and the line that caused the problem to the standard error stream. If
                    720: there are more than 20 such errors, <b>pcregrep</b> gives up.
                    721: </P>
                    722: <P>
                    723: The <b>--match-limit</b> option of <b>pcregrep</b> can be used to set the overall
                    724: resource limit; there is a second option called <b>--recursion-limit</b> that
                    725: sets a limit on the amount of memory (usually stack) that is used (see the
                    726: discussion of these options above).
                    727: </P>
1.1.1.2   misho     728: <br><a name="SEC11" href="#TOC1">DIAGNOSTICS</a><br>
1.1       misho     729: <P>
                    730: Exit status is 0 if any matches were found, 1 if no matches were found, and 2
                    731: for syntax errors, overlong lines, non-existent or inaccessible files (even if
                    732: matches were found in other files) or too many matching errors. Using the
                    733: <b>-s</b> option to suppress error messages about inaccessible files does not
                    734: affect the return code.
                    735: </P>
1.1.1.2   misho     736: <br><a name="SEC12" href="#TOC1">SEE ALSO</a><br>
1.1       misho     737: <P>
1.1.1.3 ! misho     738: <b>pcrepattern</b>(3), <b>pcresyntax</b>(3), <b>pcretest</b>(1).
1.1       misho     739: </P>
1.1.1.2   misho     740: <br><a name="SEC13" href="#TOC1">AUTHOR</a><br>
1.1       misho     741: <P>
                    742: Philip Hazel
                    743: <br>
                    744: University Computing Service
                    745: <br>
                    746: Cambridge CB2 3QH, England.
                    747: <br>
                    748: </P>
1.1.1.2   misho     749: <br><a name="SEC14" href="#TOC1">REVISION</a><br>
1.1       misho     750: <P>
1.1.1.3 ! misho     751: Last updated: 13 September 2012
1.1       misho     752: <br>
1.1.1.2   misho     753: Copyright &copy; 1997-2012 University of Cambridge.
1.1       misho     754: <br>
                    755: <p>
                    756: Return to the <a href="index.html">PCRE index page</a>.
                    757: </p>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>