Blame doc/html/pcregrep.html

Packit 78a954
<html>
Packit 78a954
<head>
Packit 78a954
<title>pcregrep specification</title>
Packit 78a954
</head>
Packit 78a954
<body bgcolor="#FFFFFF" text="#00005A" link="#0066FF" alink="#3399FF" vlink="#2222BB">
Packit 78a954

pcregrep man page

Packit 78a954

Packit 78a954
Return to the PCRE index page.
Packit 78a954

Packit 78a954

Packit 78a954
This page is part of the PCRE HTML documentation. It was generated automatically
Packit 78a954
from the original man page. If there is any nonsense in it, please consult the
Packit 78a954
man page, in case the conversion went wrong.
Packit 78a954

Packit 78a954
    Packit 78a954
  • SYNOPSIS
  • Packit 78a954
  • DESCRIPTION
  • Packit 78a954
  • SUPPORT FOR COMPRESSED FILES
  • Packit 78a954
  • BINARY FILES
  • Packit 78a954
  • OPTIONS
  • Packit 78a954
  • ENVIRONMENT VARIABLES
  • Packit 78a954
  • NEWLINES
  • Packit 78a954
  • OPTIONS COMPATIBILITY
  • Packit 78a954
  • OPTIONS WITH DATA
  • Packit 78a954
  • MATCHING ERRORS
  • Packit 78a954
  • DIAGNOSTICS
  • Packit 78a954
  • SEE ALSO
  • Packit 78a954
  • AUTHOR
  • Packit 78a954
  • REVISION
  • Packit 78a954
    Packit 78a954

    SYNOPSIS
    Packit 78a954

    Packit 78a954
    pcregrep [options] [long options] [pattern] [path1 path2 ...]
    Packit 78a954

    Packit 78a954

    DESCRIPTION
    Packit 78a954

    Packit 78a954
    pcregrep searches files for character patterns, in the same way as other
    Packit 78a954
    grep commands do, but it uses the PCRE regular expression library to support
    Packit 78a954
    patterns that are compatible with the regular expressions of Perl 5. See
    Packit 78a954
    pcresyntax(3)
    Packit 78a954
    for a quick-reference summary of pattern syntax, or
    Packit 78a954
    pcrepattern(3)
    Packit 78a954
    for a full description of the syntax and semantics of the regular expressions
    Packit 78a954
    that PCRE supports.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    Patterns, whether supplied on the command line or in a separate file, are given
    Packit 78a954
    without delimiters. For example:
    Packit 78a954
    Packit 78a954
      pcregrep Thursday /etc/motd
    Packit 78a954
    Packit 78a954
    If you attempt to use delimiters (for example, by surrounding a pattern with
    Packit 78a954
    slashes, as is common in Perl scripts), they are interpreted as part of the
    Packit 78a954
    pattern. Quotes can of course be used to delimit patterns on the command line
    Packit 78a954
    because they are interpreted by the shell, and indeed quotes are required if a
    Packit 78a954
    pattern contains white space or shell metacharacters.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    The first argument that follows any option settings is treated as the single
    Packit 78a954
    pattern to be matched when neither -e nor -f is present.
    Packit 78a954
    Conversely, when one or both of these options are used to specify patterns, all
    Packit 78a954
    arguments are treated as path names. At least one of -e, -f, or an
    Packit 78a954
    argument pattern must be provided.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    If no files are specified, pcregrep reads the standard input. The
    Packit 78a954
    standard input can also be referenced by a name consisting of a single hyphen.
    Packit 78a954
    For example:
    Packit 78a954
    Packit 78a954
      pcregrep some-pattern /file1 - /file3
    Packit 78a954
    Packit 78a954
    By default, each line that matches a pattern is copied to the standard
    Packit 78a954
    output, and if there is more than one file, the file name is output at the
    Packit 78a954
    start of each line, followed by a colon. However, there are options that can
    Packit 78a954
    change how pcregrep behaves. In particular, the -M option makes it
    Packit 78a954
    possible to search for patterns that span line boundaries. What defines a line
    Packit 78a954
    boundary is controlled by the -N (--newline) option.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    The amount of memory used for buffering files that are being scanned is
    Packit 78a954
    controlled by a parameter that can be set by the --buffer-size option.
    Packit 78a954
    The default value for this parameter is specified when pcregrep is built,
    Packit 78a954
    with the default default being 20K. A block of memory three times this size is
    Packit 78a954
    used (to allow for buffering "before" and "after" lines). An error occurs if a
    Packit 78a954
    line overflows the buffer.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    Patterns can be no longer than 8K or BUFSIZ bytes, whichever is the greater.
    Packit 78a954
    BUFSIZ is defined in <stdio.h>. When there is more than one pattern
    Packit 78a954
    (specified by the use of -e and/or -f), each pattern is applied to
    Packit 78a954
    each line in the order in which they are defined, except that all the -e
    Packit 78a954
    patterns are tried before the -f patterns.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    By default, as soon as one pattern matches a line, no further patterns are
    Packit 78a954
    considered. However, if --colour (or --color) is used to colour the
    Packit 78a954
    matching substrings, or if --only-matching, --file-offsets, or
    Packit 78a954
    --line-offsets is used to output only the part of the line that matched
    Packit 78a954
    (either shown literally, or as an offset), scanning resumes immediately
    Packit 78a954
    following the match, so that further matches on the same line can be found. If
    Packit 78a954
    there are multiple patterns, they are all tried on the remainder of the line,
    Packit 78a954
    but patterns that follow the one that matched are not tried on the earlier part
    Packit 78a954
    of the line.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    This behaviour means that the order in which multiple patterns are specified
    Packit 78a954
    can affect the output when one of the above options is used. This is no longer
    Packit 78a954
    the same behaviour as GNU grep, which now manages to display earlier matches
    Packit 78a954
    for later patterns (as long as there is no overlap).
    Packit 78a954

    Packit 78a954

    Packit 78a954
    Patterns that can match an empty string are accepted, but empty string
    Packit 78a954
    matches are never recognized. An example is the pattern "(super)?(man)?", in
    Packit 78a954
    which all components are optional. This pattern finds all occurrences of both
    Packit 78a954
    "super" and "man"; the output differs from matching with "super|man" when only
    Packit 78a954
    the matching substrings are being shown.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    If the LC_ALL or LC_CTYPE environment variable is set,
    Packit 78a954
    pcregrep uses the value to set a locale when calling the PCRE library.
    Packit 78a954
    The --locale option can be used to override this.
    Packit 78a954

    Packit 78a954

    SUPPORT FOR COMPRESSED FILES
    Packit 78a954

    Packit 78a954
    It is possible to compile pcregrep so that it uses libz or
    Packit 78a954
    libbz2 to read files whose names end in .gz or .bz2,
    Packit 78a954
    respectively. You can find out whether your binary has support for one or both
    Packit 78a954
    of these file types by running it with the --help option. If the
    Packit 78a954
    appropriate support is not present, files are treated as plain text. The
    Packit 78a954
    standard input is always so treated.
    Packit 78a954

    Packit 78a954

    BINARY FILES
    Packit 78a954

    Packit 78a954
    By default, a file that contains a binary zero byte within the first 1024 bytes
    Packit 78a954
    is identified as a binary file, and is processed specially. (GNU grep also
    Packit 78a954
    identifies binary files in this manner.) See the --binary-files option
    Packit 78a954
    for a means of changing the way binary files are handled.
    Packit 78a954

    Packit 78a954

    OPTIONS
    Packit 78a954

    Packit 78a954
    The order in which some of the options appear can affect the output. For
    Packit 78a954
    example, both the -h and -l options affect the printing of file
    Packit 78a954
    names. Whichever comes later in the command line will be the one that takes
    Packit 78a954
    effect. Similarly, except where noted below, if an option is given twice, the
    Packit 78a954
    later setting is used. Numerical values for options may be followed by K or M,
    Packit 78a954
    to signify multiplication by 1024 or 1024*1024 respectively.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    --
    Packit 78a954
    This terminates the list of options. It is useful if the next item on the
    Packit 78a954
    command line starts with a hyphen but is not an option. This allows for the
    Packit 78a954
    processing of patterns and filenames that start with hyphens.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -A number, --after-context=number
    Packit 78a954
    Output number lines of context after each matching line. If filenames
    Packit 78a954
    and/or line numbers are being output, a hyphen separator is used instead of a
    Packit 78a954
    colon for the context lines. A line containing "--" is output between each
    Packit 78a954
    group of lines, unless they are in fact contiguous in the input file. The value
    Packit 78a954
    of number is expected to be relatively small. However, pcregrep
    Packit 78a954
    guarantees to have up to 8K of following text available for context output.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -a, --text
    Packit 78a954
    Treat binary files as text. This is equivalent to
    Packit 78a954
    --binary-files=text.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -B number, --before-context=number
    Packit 78a954
    Output number lines of context before each matching line. If filenames
    Packit 78a954
    and/or line numbers are being output, a hyphen separator is used instead of a
    Packit 78a954
    colon for the context lines. A line containing "--" is output between each
    Packit 78a954
    group of lines, unless they are in fact contiguous in the input file. The value
    Packit 78a954
    of number is expected to be relatively small. However, pcregrep
    Packit 78a954
    guarantees to have up to 8K of preceding text available for context output.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    --binary-files=word
    Packit 78a954
    Specify how binary files are to be processed. If the word is "binary" (the
    Packit 78a954
    default), pattern matching is performed on binary files, but the only output is
    Packit 78a954
    "Binary file <name> matches" when a match succeeds. If the word is "text",
    Packit 78a954
    which is equivalent to the -a or --text option, binary files are
    Packit 78a954
    processed in the same way as any other file. In this case, when a match
    Packit 78a954
    succeeds, the output may be binary garbage, which can have nasty effects if
    Packit 78a954
    sent to a terminal. If the word is "without-match", which is equivalent to the
    Packit 78a954
    -I option, binary files are not processed at all; they are assumed not to
    Packit 78a954
    be of interest.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    --buffer-size=number
    Packit 78a954
    Set the parameter that controls how much memory is used for buffering files
    Packit 78a954
    that are being scanned.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -C number, --context=number
    Packit 78a954
    Output number lines of context both before and after each matching line.
    Packit 78a954
    This is equivalent to setting both -A and -B to the same value.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -c, --count
    Packit 78a954
    Do not output individual lines from the files that are being scanned; instead
    Packit 78a954
    output the number of lines that would otherwise have been shown. If no lines
    Packit 78a954
    are selected, the number zero is output. If several files are are being
    Packit 78a954
    scanned, a count is output for each of them. However, if the
    Packit 78a954
    --files-with-matches option is also used, only those files whose counts
    Packit 78a954
    are greater than zero are listed. When -c is used, the -A,
    Packit 78a954
    -B, and -C options are ignored.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    --colour, --color
    Packit 78a954
    If this option is given without any data, it is equivalent to "--colour=auto".
    Packit 78a954
    If data is required, it must be given in the same shell item, separated by an
    Packit 78a954
    equals sign.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    --colour=value, --color=value
    Packit 78a954
    This option specifies under what circumstances the parts of a line that matched
    Packit 78a954
    a pattern should be coloured in the output. By default, the output is not
    Packit 78a954
    coloured. The value (which is optional, see above) may be "never", "always", or
    Packit 78a954
    "auto". In the latter case, colouring happens only if the standard output is
    Packit 78a954
    connected to a terminal. More resources are used when colouring is enabled,
    Packit 78a954
    because pcregrep has to search for all possible matches in a line, not
    Packit 78a954
    just one, in order to colour them all.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    The colour that is used can be specified by setting the environment variable
    Packit 78a954
    PCREGREP_COLOUR or PCREGREP_COLOR. The value of this variable should be a
    Packit 78a954
    string of two numbers, separated by a semicolon. They are copied directly into
    Packit 78a954
    the control string for setting colour on a terminal, so it is your
    Packit 78a954
    responsibility to ensure that they make sense. If neither of the environment
    Packit 78a954
    variables is set, the default is "1;31", which gives red.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -D action, --devices=action
    Packit 78a954
    If an input path is not a regular file or a directory, "action" specifies how
    Packit 78a954
    it is to be processed. Valid values are "read" (the default) or "skip"
    Packit 78a954
    (silently skip the path).
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -d action, --directories=action
    Packit 78a954
    If an input path is a directory, "action" specifies how it is to be processed.
    Packit 78a954
    Valid values are "read" (the default in non-Windows environments, for
    Packit 78a954
    compatibility with GNU grep), "recurse" (equivalent to the -r option), or
    Packit 78a954
    "skip" (silently skip the path, the default in Windows environments). In the
    Packit 78a954
    "read" case, directories are read as if they were ordinary files. In some
    Packit 78a954
    operating systems the effect of reading a directory like this is an immediate
    Packit 78a954
    end-of-file; in others it may provoke an error.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -e pattern, --regex=pattern, --regexp=pattern
    Packit 78a954
    Specify a pattern to be matched. This option can be used multiple times in
    Packit 78a954
    order to specify several patterns. It can also be used as a way of specifying a
    Packit 78a954
    single pattern that starts with a hyphen. When -e is used, no argument
    Packit 78a954
    pattern is taken from the command line; all arguments are treated as file
    Packit 78a954
    names. There is no limit to the number of patterns. They are applied to each
    Packit 78a954
    line in the order in which they are defined until one matches.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    If -f is used with -e, the command line patterns are matched first,
    Packit 78a954
    followed by the patterns from the file(s), independent of the order in which
    Packit 78a954
    these options are specified. Note that multiple use of -e is not the same
    Packit 78a954
    as a single pattern with alternatives. For example, X|Y finds the first
    Packit 78a954
    character in a line that is X or Y, whereas if the two patterns are given
    Packit 78a954
    separately, with X first, pcregrep finds X if it is present, even if it
    Packit 78a954
    follows Y in the line. It finds Y only if there is no X in the line. This
    Packit 78a954
    matters only if you are using -o or --colo(u)r to show the part(s)
    Packit 78a954
    of the line that matched.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    --exclude=pattern
    Packit 78a954
    Files (but not directories) whose names match the pattern are skipped without
    Packit 78a954
    being processed. This applies to all files, whether listed on the command line,
    Packit 78a954
    obtained from --file-list, or by scanning a directory. The pattern is a
    Packit 78a954
    PCRE regular expression, and is matched against the final component of the file
    Packit 78a954
    name, not the entire path. The -F, -w, and -x options do not
    Packit 78a954
    apply to this pattern. The option may be given any number of times in order to
    Packit 78a954
    specify multiple patterns. If a file name matches both an --include
    Packit 78a954
    and an --exclude pattern, it is excluded. There is no short form for this
    Packit 78a954
    option.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    --exclude-from=filename
    Packit 78a954
    Treat each non-empty line of the file as the data for an --exclude
    Packit 78a954
    option. What constitutes a newline when reading the file is the operating
    Packit 78a954
    system's default. The --newline option has no effect on this option. This
    Packit 78a954
    option may be given more than once in order to specify a number of files to
    Packit 78a954
    read.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    --exclude-dir=pattern
    Packit 78a954
    Directories whose names match the pattern are skipped without being processed,
    Packit 78a954
    whatever the setting of the --recursive option. This applies to all
    Packit 78a954
    directories, whether listed on the command line, obtained from
    Packit 78a954
    --file-list, or by scanning a parent directory. The pattern is a PCRE
    Packit 78a954
    regular expression, and is matched against the final component of the directory
    Packit 78a954
    name, not the entire path. The -F, -w, and -x options do not
    Packit 78a954
    apply to this pattern. The option may be given any number of times in order to
    Packit 78a954
    specify more than one pattern. If a directory matches both --include-dir
    Packit 78a954
    and --exclude-dir, it is excluded. There is no short form for this
    Packit 78a954
    option.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -F, --fixed-strings
    Packit 78a954
    Interpret each data-matching pattern as a list of fixed strings, separated by
    Packit 78a954
    newlines, instead of as a regular expression. What constitutes a newline for
    Packit 78a954
    this purpose is controlled by the --newline option. The -w (match
    Packit 78a954
    as a word) and -x (match whole line) options can be used with -F.
    Packit 78a954
    They apply to each of the fixed strings. A line is selected if any of the fixed
    Packit 78a954
    strings are found in it (subject to -w or -x, if present). This
    Packit 78a954
    option applies only to the patterns that are matched against the contents of
    Packit 78a954
    files; it does not apply to patterns specified by any of the --include or
    Packit 78a954
    --exclude options.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -f filename, --file=filename
    Packit 78a954
    Read patterns from the file, one per line, and match them against
    Packit 78a954
    each line of input. What constitutes a newline when reading the file is the
    Packit 78a954
    operating system's default. The --newline option has no effect on this
    Packit 78a954
    option. Trailing white space is removed from each line, and blank lines are
    Packit 78a954
    ignored. An empty file contains no patterns and therefore matches nothing. See
    Packit 78a954
    also the comments about multiple patterns versus a single pattern with
    Packit 78a954
    alternatives in the description of -e above.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    If this option is given more than once, all the specified files are
    Packit 78a954
    read. A data line is output if any of the patterns match it. A filename can
    Packit 78a954
    be given as "-" to refer to the standard input. When -f is used, patterns
    Packit 78a954
    specified on the command line using -e may also be present; they are
    Packit 78a954
    tested before the file's patterns. However, no other pattern is taken from the
    Packit 78a954
    command line; all arguments are treated as the names of paths to be searched.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    --file-list=filename
    Packit 78a954
    Read a list of files and/or directories that are to be scanned from the given
    Packit 78a954
    file, one per line. Trailing white space is removed from each line, and blank
    Packit 78a954
    lines are ignored. These paths are processed before any that are listed on the
    Packit 78a954
    command line. The filename can be given as "-" to refer to the standard input.
    Packit 78a954
    If --file and --file-list are both specified as "-", patterns are
    Packit 78a954
    read first. This is useful only when the standard input is a terminal, from
    Packit 78a954
    which further lines (the list of files) can be read after an end-of-file
    Packit 78a954
    indication. If this option is given more than once, all the specified files are
    Packit 78a954
    read.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    --file-offsets
    Packit 78a954
    Instead of showing lines or parts of lines that match, show each match as an
    Packit 78a954
    offset from the start of the file and a length, separated by a comma. In this
    Packit 78a954
    mode, no context is shown. That is, the -A, -B, and -C
    Packit 78a954
    options are ignored. If there is more than one match in a line, each of them is
    Packit 78a954
    shown separately. This option is mutually exclusive with --line-offsets
    Packit 78a954
    and --only-matching.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -H, --with-filename
    Packit 78a954
    Force the inclusion of the filename at the start of output lines when searching
    Packit 78a954
    a single file. By default, the filename is not shown in this case. For matching
    Packit 78a954
    lines, the filename is followed by a colon; for context lines, a hyphen
    Packit 78a954
    separator is used. If a line number is also being output, it follows the file
    Packit 78a954
    name.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -h, --no-filename
    Packit 78a954
    Suppress the output filenames when searching multiple files. By default,
    Packit 78a954
    filenames are shown when multiple files are searched. For matching lines, the
    Packit 78a954
    filename is followed by a colon; for context lines, a hyphen separator is used.
    Packit 78a954
    If a line number is also being output, it follows the file name.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    --help
    Packit 78a954
    Output a help message, giving brief details of the command options and file
    Packit 78a954
    type support, and then exit. Anything else on the command line is
    Packit 78a954
    ignored.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -I
    Packit 78a954
    Treat binary files as never matching. This is equivalent to
    Packit 78a954
    --binary-files=without-match.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -i, --ignore-case
    Packit 78a954
    Ignore upper/lower case distinctions during comparisons.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    --include=pattern
    Packit 78a954
    If any --include patterns are specified, the only files that are
    Packit 78a954
    processed are those that match one of the patterns (and do not match an
    Packit 78a954
    --exclude pattern). This option does not affect directories, but it
    Packit 78a954
    applies to all files, whether listed on the command line, obtained from
    Packit 78a954
    --file-list, or by scanning a directory. The pattern is a PCRE regular
    Packit 78a954
    expression, and is matched against the final component of the file name, not
    Packit 78a954
    the entire path. The -F, -w, and -x options do not apply to
    Packit 78a954
    this pattern. The option may be given any number of times. If a file name
    Packit 78a954
    matches both an --include and an --exclude pattern, it is excluded.
    Packit 78a954
    There is no short form for this option.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    --include-from=filename
    Packit 78a954
    Treat each non-empty line of the file as the data for an --include
    Packit 78a954
    option. What constitutes a newline for this purpose is the operating system's
    Packit 78a954
    default. The --newline option has no effect on this option. This option
    Packit 78a954
    may be given any number of times; all the files are read.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    --include-dir=pattern
    Packit 78a954
    If any --include-dir patterns are specified, the only directories that
    Packit 78a954
    are processed are those that match one of the patterns (and do not match an
    Packit 78a954
    --exclude-dir pattern). This applies to all directories, whether listed
    Packit 78a954
    on the command line, obtained from --file-list, or by scanning a parent
    Packit 78a954
    directory. The pattern is a PCRE regular expression, and is matched against the
    Packit 78a954
    final component of the directory name, not the entire path. The -F,
    Packit 78a954
    -w, and -x options do not apply to this pattern. The option may be
    Packit 78a954
    given any number of times. If a directory matches both --include-dir and
    Packit 78a954
    --exclude-dir, it is excluded. There is no short form for this option.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -L, --files-without-match
    Packit 78a954
    Instead of outputting lines from the files, just output the names of the files
    Packit 78a954
    that do not contain any lines that would have been output. Each file name is
    Packit 78a954
    output once, on a separate line.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -l, --files-with-matches
    Packit 78a954
    Instead of outputting lines from the files, just output the names of the files
    Packit 78a954
    containing lines that would have been output. Each file name is output
    Packit 78a954
    once, on a separate line. Searching normally stops as soon as a matching line
    Packit 78a954
    is found in a file. However, if the -c (count) option is also used,
    Packit 78a954
    matching continues in order to obtain the correct count, and those files that
    Packit 78a954
    have at least one match are listed along with their counts. Using this option
    Packit 78a954
    with -c is a way of suppressing the listing of files with no matches.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    --label=name
    Packit 78a954
    This option supplies a name to be used for the standard input when file names
    Packit 78a954
    are being output. If not supplied, "(standard input)" is used. There is no
    Packit 78a954
    short form for this option.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    --line-buffered
    Packit 78a954
    When this option is given, input is read and processed line by line, and the
    Packit 78a954
    output is flushed after each write. By default, input is read in large chunks,
    Packit 78a954
    unless pcregrep can determine that it is reading from a terminal (which
    Packit 78a954
    is currently possible only in Unix-like environments). Output to terminal is
    Packit 78a954
    normally automatically flushed by the operating system. This option can be
    Packit 78a954
    useful when the input or output is attached to a pipe and you do not want
    Packit 78a954
    pcregrep to buffer up large amounts of data. However, its use will affect
    Packit 78a954
    performance, and the -M (multiline) option ceases to work.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    --line-offsets
    Packit 78a954
    Instead of showing lines or parts of lines that match, show each match as a
    Packit 78a954
    line number, the offset from the start of the line, and a length. The line
    Packit 78a954
    number is terminated by a colon (as usual; see the -n option), and the
    Packit 78a954
    offset and length are separated by a comma. In this mode, no context is shown.
    Packit 78a954
    That is, the -A, -B, and -C options are ignored. If there is
    Packit 78a954
    more than one match in a line, each of them is shown separately. This option is
    Packit 78a954
    mutually exclusive with --file-offsets and --only-matching.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    --locale=locale-name
    Packit 78a954
    This option specifies a locale to be used for pattern matching. It overrides
    Packit 78a954
    the value in the LC_ALL or LC_CTYPE environment variables. If no
    Packit 78a954
    locale is specified, the PCRE library's default (usually the "C" locale) is
    Packit 78a954
    used. There is no short form for this option.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    --match-limit=number
    Packit 78a954
    Processing some regular expression patterns can require a very large amount of
    Packit 78a954
    memory, leading in some cases to a program crash if not enough is available.
    Packit 78a954
    Other patterns may take a very long time to search for all possible matching
    Packit 78a954
    strings. The pcre_exec() function that is called by pcregrep to do
    Packit 78a954
    the matching has two parameters that can limit the resources that it uses.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    The --match-limit option provides a means of limiting resource usage
    Packit 78a954
    when processing patterns that are not going to match, but which have a very
    Packit 78a954
    large number of possibilities in their search trees. The classic example is a
    Packit 78a954
    pattern that uses nested unlimited repeats. Internally, PCRE uses a function
    Packit 78a954
    called match() which it calls repeatedly (sometimes recursively). The
    Packit 78a954
    limit set by --match-limit is imposed on the number of times this
    Packit 78a954
    function is called during a match, which has the effect of limiting the amount
    Packit 78a954
    of backtracking that can take place.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    The --recursion-limit option is similar to --match-limit, but
    Packit 78a954
    instead of limiting the total number of times that match() is called, it
    Packit 78a954
    limits the depth of recursive calls, which in turn limits the amount of memory
    Packit 78a954
    that can be used. The recursion depth is a smaller number than the total number
    Packit 78a954
    of calls, because not all calls to match() are recursive. This limit is
    Packit 78a954
    of use only if it is set smaller than --match-limit.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    There are no short forms for these options. The default settings are specified
    Packit 78a954
    when the PCRE library is compiled, with the default default being 10 million.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -M, --multiline
    Packit 78a954
    Allow patterns to match more than one line. When this option is given, patterns
    Packit 78a954
    may usefully contain literal newline characters and internal occurrences of ^
    Packit 78a954
    and $ characters. The output for a successful match may consist of more than
    Packit 78a954
    one line, the last of which is the one in which the match ended. If the matched
    Packit 78a954
    string ends with a newline sequence the output ends at the end of that line.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    When this option is set, the PCRE library is called in "multiline" mode.
    Packit 78a954
    There is a limit to the number of lines that can be matched, imposed by the way
    Packit 78a954
    that pcregrep buffers the input file as it scans it. However,
    Packit 78a954
    pcregrep ensures that at least 8K characters or the rest of the document
    Packit 78a954
    (whichever is the shorter) are available for forward matching, and similarly
    Packit 78a954
    the previous 8K characters (or all the previous characters, if fewer than 8K)
    Packit 78a954
    are guaranteed to be available for lookbehind assertions. This option does not
    Packit 78a954
    work when input is read line by line (see \fP--line-buffered\fP.)
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -N newline-type, --newline=newline-type
    Packit 78a954
    The PCRE library supports five different conventions for indicating
    Packit 78a954
    the ends of lines. They are the single-character sequences CR (carriage return)
    Packit 78a954
    and LF (linefeed), the two-character sequence CRLF, an "anycrlf" convention,
    Packit 78a954
    which recognizes any of the preceding three types, and an "any" convention, in
    Packit 78a954
    which any Unicode line ending sequence is assumed to end a line. The Unicode
    Packit 78a954
    sequences are the three just mentioned, plus VT (vertical tab, U+000B), FF
    Packit 78a954
    (form feed, U+000C), NEL (next line, U+0085), LS (line separator, U+2028), and
    Packit 78a954
    PS (paragraph separator, U+2029).
    Packit 78a954

    Packit 78a954

    Packit 78a954
    When the PCRE library is built, a default line-ending sequence is specified.
    Packit 78a954
    This is normally the standard sequence for the operating system. Unless
    Packit 78a954
    otherwise specified by this option, pcregrep uses the library's default.
    Packit 78a954
    The possible values for this option are CR, LF, CRLF, ANYCRLF, or ANY. This
    Packit 78a954
    makes it possible to use pcregrep to scan files that have come from other
    Packit 78a954
    environments without having to modify their line endings. If the data that is
    Packit 78a954
    being scanned does not agree with the convention set by this option,
    Packit 78a954
    pcregrep may behave in strange ways. Note that this option does not
    Packit 78a954
    apply to files specified by the -f, --exclude-from, or
    Packit 78a954
    --include-from options, which are expected to use the operating system's
    Packit 78a954
    standard newline sequence.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -n, --line-number
    Packit 78a954
    Precede each output line by its line number in the file, followed by a colon
    Packit 78a954
    for matching lines or a hyphen for context lines. If the filename is also being
    Packit 78a954
    output, it precedes the line number. This option is forced if
    Packit 78a954
    --line-offsets is used.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    --no-jit
    Packit 78a954
    If the PCRE library is built with support for just-in-time compiling (which
    Packit 78a954
    speeds up matching), pcregrep automatically makes use of this, unless it
    Packit 78a954
    was explicitly disabled at build time. This option can be used to disable the
    Packit 78a954
    use of JIT at run time. It is provided for testing and working round problems.
    Packit 78a954
    It should never be needed in normal use.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -o, --only-matching
    Packit 78a954
    Show only the part of the line that matched a pattern instead of the whole
    Packit 78a954
    line. In this mode, no context is shown. That is, the -A, -B, and
    Packit 78a954
    -C options are ignored. If there is more than one match in a line, each
    Packit 78a954
    of them is shown separately. If -o is combined with -v (invert the
    Packit 78a954
    sense of the match to find non-matching lines), no output is generated, but the
    Packit 78a954
    return code is set appropriately. If the matched portion of the line is empty,
    Packit 78a954
    nothing is output unless the file name or line number are being printed, in
    Packit 78a954
    which case they are shown on an otherwise empty line. This option is mutually
    Packit 78a954
    exclusive with --file-offsets and --line-offsets.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -onumber, --only-matching=number
    Packit 78a954
    Show only the part of the line that matched the capturing parentheses of the
    Packit 78a954
    given number. Up to 32 capturing parentheses are supported, and -o0 is
    Packit 78a954
    equivalent to -o without a number. Because these options can be given
    Packit 78a954
    without an argument (see above), if an argument is present, it must be given in
    Packit 78a954
    the same shell item, for example, -o3 or --only-matching=2. The comments given
    Packit 78a954
    for the non-argument case above also apply to this case. If the specified
    Packit 78a954
    capturing parentheses do not exist in the pattern, or were not set in the
    Packit 78a954
    match, nothing is output unless the file name or line number are being printed.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    If this option is given multiple times, multiple substrings are output, in the
    Packit 78a954
    order the options are given. For example, -o3 -o1 -o3 causes the substrings
    Packit 78a954
    matched by capturing parentheses 3 and 1 and then 3 again to be output. By
    Packit 78a954
    default, there is no separator (but see the next option).
    Packit 78a954

    Packit 78a954

    Packit 78a954
    --om-separator=text
    Packit 78a954
    Specify a separating string for multiple occurrences of -o. The default
    Packit 78a954
    is an empty string. Separating strings are never coloured.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -q, --quiet
    Packit 78a954
    Work quietly, that is, display nothing except error messages. The exit
    Packit 78a954
    status indicates whether or not any matches were found.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -r, --recursive
    Packit 78a954
    If any given path is a directory, recursively scan the files it contains,
    Packit 78a954
    taking note of any --include and --exclude settings. By default, a
    Packit 78a954
    directory is read as a normal file; in some operating systems this gives an
    Packit 78a954
    immediate end-of-file. This option is a shorthand for setting the -d
    Packit 78a954
    option to "recurse".
    Packit 78a954

    Packit 78a954

    Packit 78a954
    --recursion-limit=number
    Packit 78a954
    See --match-limit above.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -s, --no-messages
    Packit 78a954
    Suppress error messages about non-existent or unreadable files. Such files are
    Packit 78a954
    quietly skipped. However, the return code is still 2, even if matches were
    Packit 78a954
    found in other files.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -u, --utf-8
    Packit 78a954
    Operate in UTF-8 mode. This option is available only if PCRE has been compiled
    Packit 78a954
    with UTF-8 support. All patterns (including those for any --exclude and
    Packit 78a954
    --include options) and all subject lines that are scanned must be valid
    Packit 78a954
    strings of UTF-8 characters.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -V, --version
    Packit 78a954
    Write the version numbers of pcregrep and the PCRE library to the
    Packit 78a954
    standard output and then exit. Anything else on the command line is
    Packit 78a954
    ignored.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -v, --invert-match
    Packit 78a954
    Invert the sense of the match, so that lines which do not match any of
    Packit 78a954
    the patterns are the ones that are found.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -w, --word-regex, --word-regexp
    Packit 78a954
    Force the patterns to match only whole words. This is equivalent to having \b
    Packit 78a954
    at the start and end of the pattern. This option applies only to the patterns
    Packit 78a954
    that are matched against the contents of files; it does not apply to patterns
    Packit 78a954
    specified by any of the --include or --exclude options.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    -x, --line-regex, --line-regexp
    Packit 78a954
    Force the patterns to be anchored (each must start matching at the beginning of
    Packit 78a954
    a line) and in addition, require them to match entire lines. This is equivalent
    Packit 78a954
    to having ^ and $ characters at the start and end of each alternative branch in
    Packit 78a954
    every pattern. This option applies only to the patterns that are matched
    Packit 78a954
    against the contents of files; it does not apply to patterns specified by any
    Packit 78a954
    of the --include or --exclude options.
    Packit 78a954

    Packit 78a954

    ENVIRONMENT VARIABLES
    Packit 78a954

    Packit 78a954
    The environment variables LC_ALL and LC_CTYPE are examined, in that
    Packit 78a954
    order, for a locale. The first one that is set is used. This can be overridden
    Packit 78a954
    by the --locale option. If no locale is set, the PCRE library's default
    Packit 78a954
    (usually the "C" locale) is used.
    Packit 78a954

    Packit 78a954

    NEWLINES
    Packit 78a954

    Packit 78a954
    The -N (--newline) option allows pcregrep to scan files with
    Packit 78a954
    different newline conventions from the default. Any parts of the input files
    Packit 78a954
    that are written to the standard output are copied identically, with whatever
    Packit 78a954
    newline sequences they have in the input. However, the setting of this option
    Packit 78a954
    does not affect the interpretation of files specified by the -f,
    Packit 78a954
    --exclude-from, or --include-from options, which are assumed to use
    Packit 78a954
    the operating system's standard newline sequence, nor does it affect the way in
    Packit 78a954
    which pcregrep writes informational messages to the standard error and
    Packit 78a954
    output streams. For these it uses the string "\n" to indicate newlines,
    Packit 78a954
    relying on the C I/O library to convert this to an appropriate sequence.
    Packit 78a954

    Packit 78a954

    OPTIONS COMPATIBILITY
    Packit 78a954

    Packit 78a954
    Many of the short and long forms of pcregrep's options are the same
    Packit 78a954
    as in the GNU grep program. Any long option of the form
    Packit 78a954
    --xxx-regexp (GNU terminology) is also available as --xxx-regex
    Packit 78a954
    (PCRE terminology). However, the --file-list, --file-offsets,
    Packit 78a954
    --include-dir, --line-offsets, --locale, --match-limit,
    Packit 78a954
    -M, --multiline, -N, --newline, --om-separator,
    Packit 78a954
    --recursion-limit, -u, and --utf-8 options are specific to
    Packit 78a954
    pcregrep, as is the use of the --only-matching option with a
    Packit 78a954
    capturing parentheses number.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    Although most of the common options work the same way, a few are different in
    Packit 78a954
    pcregrep. For example, the --include option's argument is a glob
    Packit 78a954
    for GNU grep, but a regular expression for pcregrep. If both the
    Packit 78a954
    -c and -l options are given, GNU grep lists only file names,
    Packit 78a954
    without counts, but pcregrep gives the counts.
    Packit 78a954

    Packit 78a954

    OPTIONS WITH DATA
    Packit 78a954

    Packit 78a954
    There are four different ways in which an option with data can be specified.
    Packit 78a954
    If a short form option is used, the data may follow immediately, or (with one
    Packit 78a954
    exception) in the next command line item. For example:
    Packit 78a954
    Packit 78a954
      -f/some/file
    Packit 78a954
      -f /some/file
    Packit 78a954
    Packit 78a954
    The exception is the -o option, which may appear with or without data.
    Packit 78a954
    Because of this, if data is present, it must follow immediately in the same
    Packit 78a954
    item, for example -o3.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    If a long form option is used, the data may appear in the same command line
    Packit 78a954
    item, separated by an equals character, or (with two exceptions) it may appear
    Packit 78a954
    in the next command line item. For example:
    Packit 78a954
    Packit 78a954
      --file=/some/file
    Packit 78a954
      --file /some/file
    Packit 78a954
    Packit 78a954
    Note, however, that if you want to supply a file name beginning with ~ as data
    Packit 78a954
    in a shell command, and have the shell expand ~ to a home directory, you must
    Packit 78a954
    separate the file name from the option, because the shell does not treat ~
    Packit 78a954
    specially unless it is at the start of an item.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    The exceptions to the above are the --colour (or --color) and
    Packit 78a954
    --only-matching options, for which the data is optional. If one of these
    Packit 78a954
    options does have data, it must be given in the first form, using an equals
    Packit 78a954
    character. Otherwise pcregrep will assume that it has no data.
    Packit 78a954

    Packit 78a954

    MATCHING ERRORS
    Packit 78a954

    Packit 78a954
    It is possible to supply a regular expression that takes a very long time to
    Packit 78a954
    fail to match certain lines. Such patterns normally involve nested indefinite
    Packit 78a954
    repeats, for example: (a+)*\d when matched against a line of a's with no final
    Packit 78a954
    digit. The PCRE matching function has a resource limit that causes it to abort
    Packit 78a954
    in these circumstances. If this happens, pcregrep outputs an error
    Packit 78a954
    message and the line that caused the problem to the standard error stream. If
    Packit 78a954
    there are more than 20 such errors, pcregrep gives up.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    The --match-limit option of pcregrep can be used to set the overall
    Packit 78a954
    resource limit; there is a second option called --recursion-limit that
    Packit 78a954
    sets a limit on the amount of memory (usually stack) that is used (see the
    Packit 78a954
    discussion of these options above).
    Packit 78a954

    Packit 78a954

    DIAGNOSTICS
    Packit 78a954

    Packit 78a954
    Exit status is 0 if any matches were found, 1 if no matches were found, and 2
    Packit 78a954
    for syntax errors, overlong lines, non-existent or inaccessible files (even if
    Packit 78a954
    matches were found in other files) or too many matching errors. Using the
    Packit 78a954
    -s option to suppress error messages about inaccessible files does not
    Packit 78a954
    affect the return code.
    Packit 78a954

    Packit 78a954

    SEE ALSO
    Packit 78a954

    Packit 78a954
    pcrepattern(3), pcresyntax(3), pcretest(1).
    Packit 78a954

    Packit 78a954

    AUTHOR
    Packit 78a954

    Packit 78a954
    Philip Hazel
    Packit 78a954

    Packit 78a954
    University Computing Service
    Packit 78a954

    Packit 78a954
    Cambridge CB2 3QH, England.
    Packit 78a954

    Packit 78a954

    Packit 78a954

    REVISION
    Packit 78a954

    Packit 78a954
    Last updated: 03 April 2014
    Packit 78a954

    Packit 78a954
    Copyright © 1997-2014 University of Cambridge.
    Packit 78a954

    Packit 78a954

    Packit 78a954
    Return to the PCRE index page.
    Packit 78a954