| 1 |
NAME
|
| 2 |
pcregrep - a grep with Perl-compatible regular expressions.
|
| 3 |
|
| 4 |
|
| 5 |
SYNOPSIS
|
| 6 |
pcregrep [-Vcfhilnrsuvx] [long options] [pattern] [file1
|
| 7 |
|
| 8 |
|
| 9 |
DESCRIPTION
|
| 10 |
|
| 11 |
pcregrep searches files for character patterns, in the same
|
| 12 |
way as other grep commands do, but it uses the PCRE regular
|
| 13 |
expression library to support patterns that are compatible
|
| 14 |
with the regular expressions of Perl 5. See pcrepattern for
|
| 15 |
a full description of syntax and semantics of the regular
|
| 16 |
expressions that PCRE supports.
|
| 17 |
|
| 18 |
A pattern must be specified on the command line unless the
|
| 19 |
-f option is used (see below).
|
| 20 |
|
| 21 |
If no files are specified, pcregrep reads the standard
|
| 22 |
input. By default, each line that matches the pattern is
|
| 23 |
copied to the standard output, and if there is more than one
|
| 24 |
file, the file name is printed before each line of output.
|
| 25 |
However, there are options that can change how pcregrep
|
| 26 |
behaves.
|
| 27 |
|
| 28 |
Lines are limited to BUFSIZ characters. BUFSIZ is defined in
|
| 29 |
<stdio.h>. The newline character is removed from the end of
|
| 30 |
each line before it is matched against the pattern.
|
| 31 |
|
| 32 |
|
| 33 |
OPTIONS
|
| 34 |
|
| 35 |
|
| 36 |
-V Write the version number of the PCRE library being
|
| 37 |
used to the standard error stream.
|
| 38 |
|
| 39 |
-c Do not print individual lines; instead just print
|
| 40 |
a count of the number of lines that would other-
|
| 41 |
wise have been printed. If several files are
|
| 42 |
given, a count is printed for each of them.
|
| 43 |
|
| 44 |
-ffilename
|
| 45 |
Read a number of patterns from the file, one per
|
| 46 |
line, and match all of them against each line of
|
| 47 |
input. A line is output if any of the patterns
|
| 48 |
match it. When -f is used, no pattern is taken
|
| 49 |
from the command line; all arguments are treated
|
| 50 |
as file names. There is a maximum of 100 patterns.
|
| 51 |
Trailing white space is removed, and blank lines
|
| 52 |
are ignored. An empty file contains no patterns
|
| 53 |
and therefore matches nothing.
|
| 54 |
|
| 55 |
-h Suppress printing of filenames when searching mul-
|
| 56 |
tiple files.
|
| 57 |
|
| 58 |
-i Ignore upper/lower case distinctions during com-
|
| 59 |
parisons.
|
| 60 |
|
| 61 |
-l Instead of printing lines from the files, just
|
| 62 |
print the names of the files containing lines that
|
| 63 |
would have been printed. Each file name is printed
|
| 64 |
once, on a separate line.
|
| 65 |
|
| 66 |
-n Precede each line by its line number in the file.
|
| 67 |
|
| 68 |
-r If any file is a directory, recursively scan the
|
| 69 |
files it contains. Without -r a directory is
|
| 70 |
scanned as a normal file.
|
| 71 |
|
| 72 |
-s Work silently, that is, display nothing except
|
| 73 |
error messages. The exit status indicates whether
|
| 74 |
any matches were found.
|
| 75 |
|
| 76 |
-u Operate in UTF-8 mode. This option is available
|
| 77 |
only if PCRE has been compiled with UTF-8 support.
|
| 78 |
Both the pattern and each subject line are assumed
|
| 79 |
to be valid strings of UTF-8 characters.
|
| 80 |
|
| 81 |
-v Invert the sense of the match, so that lines which
|
| 82 |
do not match the pattern are now the ones that are
|
| 83 |
found.
|
| 84 |
|
| 85 |
-x Force the pattern to be anchored (it must start
|
| 86 |
matching at the beginning of the line) and in
|
| 87 |
addition, require it to match the entire line.
|
| 88 |
This is equivalent to having ^ and $ characters at
|
| 89 |
the start and end of each alternative branch in
|
| 90 |
the regular expression.
|
| 91 |
|
| 92 |
|
| 93 |
LONG OPTIONS
|
| 94 |
|
| 95 |
Long forms of all the options are available, as in GNU grep.
|
| 96 |
They are shown in the following table:
|
| 97 |
|
| 98 |
-c --count
|
| 99 |
-h --no-filename
|
| 100 |
-i --ignore-case
|
| 101 |
-l --files-with-matches
|
| 102 |
-n --line-number
|
| 103 |
-r --recursive
|
| 104 |
-s --no-messages
|
| 105 |
-u --utf-8
|
| 106 |
-V --version
|
| 107 |
-v --invert-match
|
| 108 |
-x --line-regex
|
| 109 |
-x --line-regexp
|
| 110 |
|
| 111 |
In addition, --file=filename is equivalent to -ffilename,
|
| 112 |
and --help shows the list of options and then exits.
|
| 113 |
|
| 114 |
|
| 115 |
DIAGNOSTICS
|
| 116 |
|
| 117 |
Exit status is 0 if any matches were found, 1 if no matches
|
| 118 |
were found, and 2 for syntax errors or inacessible files
|
| 119 |
(even if matches were found).
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
AUTHOR
|
| 124 |
|
| 125 |
Philip Hazel <ph10@cam.ac.uk>
|
| 126 |
University Computing Service
|
| 127 |
Cambridge CB2 3QG, England.
|
| 128 |
|
| 129 |
Last updated: 03 February 2003
|
| 130 |
Copyright (c) 1997-2003 University of Cambridge.
|