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