github的一些开源项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1018 lines
52 KiB

  1. .TH PCRE2GREP 1 "22 December 2023" "PCRE2 10.43"
  2. .SH NAME
  3. pcre2grep - a grep with Perl-compatible regular expressions.
  4. .SH SYNOPSIS
  5. .B pcre2grep [options] [long options] [pattern] [path1 path2 ...]
  6. .
  7. .SH DESCRIPTION
  8. .rs
  9. .sp
  10. \fBpcre2grep\fP searches files for character patterns, in the same way as other
  11. grep commands do, but it uses the PCRE2 regular expression library to support
  12. patterns that are compatible with the regular expressions of Perl 5. See
  13. .\" HREF
  14. \fBpcre2syntax\fP(3)
  15. .\"
  16. for a quick-reference summary of pattern syntax, or
  17. .\" HREF
  18. \fBpcre2pattern\fP(3)
  19. .\"
  20. for a full description of the syntax and semantics of the regular expressions
  21. that PCRE2 supports.
  22. .P
  23. Patterns, whether supplied on the command line or in a separate file, are given
  24. without delimiters. For example:
  25. .sp
  26. pcre2grep Thursday /etc/motd
  27. .sp
  28. If you attempt to use delimiters (for example, by surrounding a pattern with
  29. slashes, as is common in Perl scripts), they are interpreted as part of the
  30. pattern. Quotes can of course be used to delimit patterns on the command line
  31. because they are interpreted by the shell, and indeed quotes are required if a
  32. pattern contains white space or shell metacharacters.
  33. .P
  34. The first argument that follows any option settings is treated as the single
  35. pattern to be matched when neither \fB-e\fP nor \fB-f\fP is present.
  36. Conversely, when one or both of these options are used to specify patterns, all
  37. arguments are treated as path names. At least one of \fB-e\fP, \fB-f\fP, or an
  38. argument pattern must be provided.
  39. .P
  40. If no files are specified, \fBpcre2grep\fP reads the standard input. The
  41. standard input can also be referenced by a name consisting of a single hyphen.
  42. For example:
  43. .sp
  44. pcre2grep some-pattern file1 - file3
  45. .sp
  46. By default, input files are searched line by line, so pattern assertions about
  47. the beginning and end of a subject string (^, $, \eA, \eZ, and \ez) match at
  48. the beginning and end of each line. When a line matches a pattern, it is copied
  49. to the standard output, and if there is more than one file, the file name is
  50. output at the start of each line, followed by a colon. However, there are
  51. options that can change how \fBpcre2grep\fP behaves. For example, the \fB-M\fP
  52. option makes it possible to search for strings that span line boundaries. What
  53. defines a line boundary is controlled by the \fB-N\fP (\fB--newline\fP) option.
  54. The \fB-h\fP and \fB-H\fP options control whether or not file names are shown,
  55. and the \fB-Z\fP option changes the file name terminator to a zero byte.
  56. .P
  57. The amount of memory used for buffering files that are being scanned is
  58. controlled by parameters that can be set by the \fB--buffer-size\fP and
  59. \fB--max-buffer-size\fP options. The first of these sets the size of buffer
  60. that is obtained at the start of processing. If an input file contains very
  61. long lines, a larger buffer may be needed; this is handled by automatically
  62. extending the buffer, up to the limit specified by \fB--max-buffer-size\fP. The
  63. default values for these parameters can be set when \fBpcre2grep\fP is
  64. built; if nothing is specified, the defaults are set to 20KiB and 1MiB
  65. respectively. An error occurs if a line is too long and the buffer can no
  66. longer be expanded.
  67. .P
  68. The block of memory that is actually used is three times the "buffer size", to
  69. allow for buffering "before" and "after" lines. If the buffer size is too
  70. small, fewer than requested "before" and "after" lines may be output.
  71. .P
  72. When matching with a multiline pattern, the size of the buffer must be at least
  73. half of the maximum match expected or the pattern might fail to match.
  74. .P
  75. Patterns can be no longer than 8KiB or BUFSIZ bytes, whichever is the greater.
  76. BUFSIZ is defined in \fB<stdio.h>\fP. When there is more than one pattern
  77. (specified by the use of \fB-e\fP and/or \fB-f\fP), each pattern is applied to
  78. each line in the order in which they are defined, except that all the \fB-e\fP
  79. patterns are tried before the \fB-f\fP patterns.
  80. .P
  81. By default, as soon as one pattern matches a line, no further patterns are
  82. considered. However, if \fB--colour\fP (or \fB--color\fP) is used to colour the
  83. matching substrings, or if \fB--only-matching\fP, \fB--file-offsets\fP,
  84. \fB--line-offsets\fP, or \fB--output\fP is used to output only the part of the
  85. line that matched (either shown literally, or as an offset), the behaviour is
  86. different. In this situation, all the patterns are applied to the line. If
  87. there is more than one match, the one that begins nearest to the start of the
  88. subject is processed; if there is more than one match at that position, the one
  89. with the longest matching substring is processed; if the matching substrings
  90. are equal, the first match found is processed.
  91. .P
  92. Scanning with all the patterns resumes immediately following the match, so that
  93. later matches on the same line can be found. Note, however, that an overlapping
  94. match that starts in the middle of another match will not be processed.
  95. .P
  96. The above behaviour was changed at release 10.41 to be more compatible with GNU
  97. grep. In earlier releases, \fBpcre2grep\fP did not recognize matches from
  98. later patterns that were earlier in the subject.
  99. .P
  100. Patterns that can match an empty string are accepted, but empty string
  101. matches are never recognized. An example is the pattern "(super)?(man)?", in
  102. which all components are optional. This pattern finds all occurrences of both
  103. "super" and "man"; the output differs from matching with "super|man" when only
  104. the matching substrings are being shown.
  105. .P
  106. If the \fBLC_ALL\fP or \fBLC_CTYPE\fP environment variable is set,
  107. \fBpcre2grep\fP uses the value to set a locale when calling the PCRE2 library.
  108. The \fB--locale\fP option can be used to override this.
  109. .
  110. .
  111. .SH "SUPPORT FOR COMPRESSED FILES"
  112. .rs
  113. .sp
  114. Compile-time options for \fBpcre2grep\fP can set it up to use \fBlibz\fP or
  115. \fBlibbz2\fP for reading compressed files whose names end in \fB.gz\fP or
  116. \fB.bz2\fP, respectively. You can find out whether your \fBpcre2grep\fP binary
  117. has support for one or both of these file types by running it with the
  118. \fB--help\fP option. If the appropriate support is not present, all files are
  119. treated as plain text. The standard input is always so treated. If a file with
  120. a \fB.gz\fP or \fB.bz2\fP extension is not in fact compressed, it is read as a
  121. plain text file. When input is from a compressed .gz or .bz2 file, the
  122. \fB--line-buffered\fP option is ignored.
  123. .
  124. .
  125. .SH "BINARY FILES"
  126. .rs
  127. .sp
  128. By default, a file that contains a binary zero byte within the first 1024 bytes
  129. is identified as a binary file, and is processed specially. However, if the
  130. newline type is specified as NUL, that is, the line terminator is a binary
  131. zero, the test for a binary file is not applied. See the \fB--binary-files\fP
  132. option for a means of changing the way binary files are handled.
  133. .
  134. .
  135. .SH "BINARY ZEROS IN PATTERNS"
  136. .rs
  137. .sp
  138. Patterns passed from the command line are strings that are terminated by a
  139. binary zero, so cannot contain internal zeros. However, patterns that are read
  140. from a file via the \fB-f\fP option may contain binary zeros.
  141. .
  142. .
  143. .SH OPTIONS
  144. .rs
  145. .sp
  146. The order in which some of the options appear can affect the output. For
  147. example, both the \fB-H\fP and \fB-l\fP options affect the printing of file
  148. names. Whichever comes later in the command line will be the one that takes
  149. effect. Similarly, except where noted below, if an option is given twice, the
  150. later setting is used. Numerical values for options may be followed by K or M,
  151. to signify multiplication by 1024 or 1024*1024 respectively.
  152. .TP 10
  153. \fB--\fP
  154. This terminates the list of options. It is useful if the next item on the
  155. command line starts with a hyphen but is not an option. This allows for the
  156. processing of patterns and file names that start with hyphens.
  157. .TP
  158. \fB-A\fP \fInumber\fP, \fB--after-context=\fP\fInumber\fP
  159. Output up to \fInumber\fP lines of context after each matching line. Fewer
  160. lines are output if the next match or the end of the file is reached, or if the
  161. processing buffer size has been set too small. If file names and/or line
  162. numbers are being output, a hyphen separator is used instead of a colon for the
  163. context lines (the \fB-Z\fP option can be used to change the file name
  164. terminator to a zero byte). A line containing "--" is output between each group
  165. of lines, unless they are in fact contiguous in the input file. The value of
  166. \fInumber\fP is expected to be relatively small. When \fB-c\fP is used,
  167. \fB-A\fP is ignored.
  168. .TP
  169. \fB-a\fP, \fB--text\fP
  170. Treat binary files as text. This is equivalent to
  171. \fB--binary-files\fP=\fItext\fP.
  172. .TP
  173. \fB--allow-lookaround-bsk\fP
  174. PCRE2 now forbids the use of \eK in lookarounds by default, in line with Perl.
  175. This option causes \fBpcre2grep\fP to set the PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK
  176. option, which enables this somewhat dangerous usage.
  177. .TP
  178. \fB-B\fP \fInumber\fP, \fB--before-context=\fP\fInumber\fP
  179. Output up to \fInumber\fP lines of context before each matching line. Fewer
  180. lines are output if the previous match or the start of the file is within
  181. \fInumber\fP lines, or if the processing buffer size has been set too small. If
  182. file names and/or line numbers are being output, a hyphen separator is used
  183. instead of a colon for the context lines (the \fB-Z\fP option can be used to
  184. change the file name terminator to a zero byte). A line containing "--" is
  185. output between each group of lines, unless they are in fact contiguous in the
  186. input file. The value of \fInumber\fP is expected to be relatively small. When
  187. \fB-c\fP is used, \fB-B\fP is ignored.
  188. .TP
  189. \fB--binary-files=\fP\fIword\fP
  190. Specify how binary files are to be processed. If the word is "binary" (the
  191. default), pattern matching is performed on binary files, but the only output is
  192. "Binary file <name> matches" when a match succeeds. If the word is "text",
  193. which is equivalent to the \fB-a\fP or \fB--text\fP option, binary files are
  194. processed in the same way as any other file. In this case, when a match
  195. succeeds, the output may be binary garbage, which can have nasty effects if
  196. sent to a terminal. If the word is "without-match", which is equivalent to the
  197. \fB-I\fP option, binary files are not processed at all; they are assumed not to
  198. be of interest and are skipped without causing any output or affecting the
  199. return code.
  200. .TP
  201. \fB--buffer-size=\fP\fInumber\fP
  202. Set the parameter that controls how much memory is obtained at the start of
  203. processing for buffering files that are being scanned. See also
  204. \fB--max-buffer-size\fP below.
  205. .TP
  206. \fB-C\fP \fInumber\fP, \fB--context=\fP\fInumber\fP
  207. Output \fInumber\fP lines of context both before and after each matching line.
  208. This is equivalent to setting both \fB-A\fP and \fB-B\fP to the same value.
  209. .TP
  210. \fB-c\fP, \fB--count\fP
  211. Do not output lines from the files that are being scanned; instead output the
  212. number of lines that would have been shown, either because they matched, or, if
  213. \fB-v\fP is set, because they failed to match. By default, this count is
  214. exactly the same as the number of lines that would have been output, but if the
  215. \fB-M\fP (multiline) option is used (without \fB-v\fP), there may be more
  216. suppressed lines than the count (that is, the number of matches).
  217. .sp
  218. If no lines are selected, the number zero is output. If several files are
  219. being scanned, a count is output for each of them and the \fB-t\fP option can
  220. be used to cause a total to be output at the end. However, if the
  221. \fB--files-with-matches\fP option is also used, only those files whose counts
  222. are greater than zero are listed. When \fB-c\fP is used, the \fB-A\fP,
  223. \fB-B\fP, and \fB-C\fP options are ignored.
  224. .TP
  225. \fB--colour\fP, \fB--color\fP
  226. If this option is given without any data, it is equivalent to "--colour=auto".
  227. If data is required, it must be given in the same shell item, separated by an
  228. equals sign.
  229. .TP
  230. \fB--colour=\fP\fIvalue\fP, \fB--color=\fP\fIvalue\fP
  231. This option specifies under what circumstances the parts of a line that matched
  232. a pattern should be coloured in the output. It is ignored if
  233. \fB--file-offsets\fP, \fB--line-offsets\fP, or \fB--output\fP is set. By
  234. default, output is not coloured. The value for the \fB--colour\fP option (which
  235. is optional, see above) may be "never", "always", or "auto". In the latter
  236. case, colouring happens only if the standard output is connected to a terminal.
  237. More resources are used when colouring is enabled, because \fBpcre2grep\fP has
  238. to search for all possible matches in a line, not just one, in order to colour
  239. them all.
  240. .sp
  241. The colour that is used can be specified by setting one of the environment
  242. variables PCRE2GREP_COLOUR, PCRE2GREP_COLOR, PCREGREP_COLOUR, or
  243. PCREGREP_COLOR, which are checked in that order. If none of these are set,
  244. \fBpcre2grep\fP looks for GREP_COLORS or GREP_COLOR (in that order). The value
  245. of the variable should be a string of two numbers, separated by a semicolon,
  246. except in the case of GREP_COLORS, which must start with "ms=" or "mt="
  247. followed by two semicolon-separated colours, terminated by the end of the
  248. string or by a colon. If GREP_COLORS does not start with "ms=" or "mt=" it is
  249. ignored, and GREP_COLOR is checked.
  250. .sp
  251. If the string obtained from one of the above variables contains any characters
  252. other than semicolon or digits, the setting is ignored and the default colour
  253. is used. The string is copied directly into the control string for setting
  254. colour on a terminal, so it is your responsibility to ensure that the values
  255. make sense. If no relevant environment variable is set, the default is "1;31",
  256. which gives red.
  257. .TP
  258. \fB-D\fP \fIaction\fP, \fB--devices=\fP\fIaction\fP
  259. If an input path is not a regular file or a directory, "action" specifies how
  260. it is to be processed. Valid values are "read" (the default) or "skip"
  261. (silently skip the path).
  262. .TP
  263. \fB-d\fP \fIaction\fP, \fB--directories=\fP\fIaction\fP
  264. If an input path is a directory, "action" specifies how it is to be processed.
  265. Valid values are "read" (the default in non-Windows environments, for
  266. compatibility with GNU grep), "recurse" (equivalent to the \fB-r\fP option), or
  267. "skip" (silently skip the path, the default in Windows environments). In the
  268. "read" case, directories are read as if they were ordinary files. In some
  269. operating systems the effect of reading a directory like this is an immediate
  270. end-of-file; in others it may provoke an error.
  271. .TP
  272. \fB--depth-limit\fP=\fInumber\fP
  273. See \fB--match-limit\fP below.
  274. .TP
  275. \fB-E\fP, \fB--case-restrict\fP
  276. When case distinctions are being ignored in Unicode mode, two ASCII letters (K
  277. and S) will by default match Unicode characters U+212A (Kelvin sign) and U+017F
  278. (long S) respectively, as well as their lower case ASCII counterparts. When
  279. this option is set, case equivalences are restricted such that no ASCII
  280. character matches a non-ASCII character, and vice versa.
  281. .TP
  282. \fB-e\fP \fIpattern\fP, \fB--regex=\fP\fIpattern\fP, \fB--regexp=\fP\fIpattern\fP
  283. Specify a pattern to be matched. This option can be used multiple times in
  284. order to specify several patterns. It can also be used as a way of specifying a
  285. single pattern that starts with a hyphen. When \fB-e\fP is used, no argument
  286. pattern is taken from the command line; all arguments are treated as file
  287. names. There is no limit to the number of patterns. They are applied to each
  288. line in the order in which they are defined.
  289. .sp
  290. If \fB-f\fP is used with \fB-e\fP, the command line patterns are matched first,
  291. followed by the patterns from the file(s), independent of the order in which
  292. these options are specified.
  293. .TP
  294. \fB--exclude\fP=\fIpattern\fP
  295. Files (but not directories) whose names match the pattern are skipped without
  296. being processed. This applies to all files, whether listed on the command line,
  297. obtained from \fB--file-list\fP, or by scanning a directory. The pattern is a
  298. PCRE2 regular expression, and is matched against the final component of the
  299. file name, not the entire path. The \fB-F\fP, \fB-w\fP, and \fB-x\fP options do
  300. not apply to this pattern. The option may be given any number of times in order
  301. to specify multiple patterns. If a file name matches both an \fB--include\fP
  302. and an \fB--exclude\fP pattern, it is excluded. There is no short form for this
  303. option.
  304. .TP
  305. \fB--exclude-from=\fP\fIfilename\fP
  306. Treat each non-empty line of the file as the data for an \fB--exclude\fP
  307. option. What constitutes a newline when reading the file is the operating
  308. system's default. The \fB--newline\fP option has no effect on this option. This
  309. option may be given more than once in order to specify a number of files to
  310. read.
  311. .TP
  312. \fB--exclude-dir\fP=\fIpattern\fP
  313. Directories whose names match the pattern are skipped without being processed,
  314. whatever the setting of the \fB--recursive\fP option. This applies to all
  315. directories, whether listed on the command line, obtained from
  316. \fB--file-list\fP, or by scanning a parent directory. The pattern is a PCRE2
  317. regular expression, and is matched against the final component of the directory
  318. name, not the entire path. The \fB-F\fP, \fB-w\fP, and \fB-x\fP options do not
  319. apply to this pattern. The option may be given any number of times in order to
  320. specify more than one pattern. If a directory matches both \fB--include-dir\fP
  321. and \fB--exclude-dir\fP, it is excluded. There is no short form for this
  322. option.
  323. .TP
  324. \fB-F\fP, \fB--fixed-strings\fP
  325. Interpret each data-matching pattern as a list of fixed strings, separated by
  326. newlines, instead of as a regular expression. What constitutes a newline for
  327. this purpose is controlled by the \fB--newline\fP option. The \fB-w\fP (match
  328. as a word) and \fB-x\fP (match whole line) options can be used with \fB-F\fP.
  329. They apply to each of the fixed strings. A line is selected if any of the fixed
  330. strings are found in it (subject to \fB-w\fP or \fB-x\fP, if present). This
  331. option applies only to the patterns that are matched against the contents of
  332. files; it does not apply to patterns specified by any of the \fB--include\fP or
  333. \fB--exclude\fP options.
  334. .TP
  335. \fB-f\fP \fIfilename\fP, \fB--file=\fP\fIfilename\fP
  336. Read patterns from the file, one per line. As is the case with patterns on the
  337. command line, no delimiters should be used. What constitutes a newline when
  338. reading the file is the operating system's default interpretation of \en. The
  339. \fB--newline\fP option has no effect on this option. Trailing white space is
  340. removed from each line, and blank lines are ignored. An empty file contains no
  341. patterns and therefore matches nothing. Patterns read from a file in this way
  342. may contain binary zeros, which are treated as ordinary data characters.
  343. .sp
  344. If this option is given more than once, all the specified files are read. A
  345. data line is output if any of the patterns match it. A file name can be given
  346. as "-" to refer to the standard input. When \fB-f\fP is used, patterns
  347. specified on the command line using \fB-e\fP may also be present; they are
  348. matched before the file's patterns. However, no pattern is taken from the
  349. command line; all arguments are treated as the names of paths to be searched.
  350. .TP
  351. \fB--file-list\fP=\fIfilename\fP
  352. Read a list of files and/or directories that are to be scanned from the given
  353. file, one per line. What constitutes a newline when reading the file is the
  354. operating system's default. Trailing white space is removed from each line, and
  355. blank lines are ignored. These paths are processed before any that are listed
  356. on the command line. The file name can be given as "-" to refer to the standard
  357. input. If \fB--file\fP and \fB--file-list\fP are both specified as "-",
  358. patterns are read first. This is useful only when the standard input is a
  359. terminal, from which further lines (the list of files) can be read after an
  360. end-of-file indication. If this option is given more than once, all the
  361. specified files are read.
  362. .TP
  363. \fB--file-offsets\fP
  364. Instead of showing lines or parts of lines that match, show each match as an
  365. offset from the start of the file and a length, separated by a comma. In this
  366. mode, \fB--colour\fP has no effect, and no context is shown. That is, the
  367. \fB-A\fP, \fB-B\fP, and \fB-C\fP options are ignored. If there is more than one
  368. match in a line, each of them is shown separately. This option is mutually
  369. exclusive with \fB--output\fP, \fB--line-offsets\fP, and \fB--only-matching\fP.
  370. .TP
  371. \fB--group-separator\fP=\fItext\fP
  372. Output this text string instead of two hyphens between groups of lines when
  373. \fB-A\fP, \fB-B\fP, or \fB-C\fP is in use. See also \fB--no-group-separator\fP.
  374. .TP
  375. \fB-H\fP, \fB--with-filename\fP
  376. Force the inclusion of the file name at the start of output lines when
  377. searching a single file. The file name is not normally shown in this case.
  378. By default, for matching lines, the file name is followed by a colon; for
  379. context lines, a hyphen separator is used. The \fB-Z\fP option can be used to
  380. change the terminator to a zero byte. If a line number is also being output,
  381. it follows the file name. When the \fB-M\fP option causes a pattern to match
  382. more than one line, only the first is preceded by the file name. This option
  383. overrides any previous \fB-h\fP, \fB-l\fP, or \fB-L\fP options.
  384. .TP
  385. \fB-h\fP, \fB--no-filename\fP
  386. Suppress the output file names when searching multiple files. File names are
  387. normally shown when multiple files are searched. By default, for matching
  388. lines, the file name is followed by a colon; for context lines, a hyphen
  389. separator is used. The \fB-Z\fP option can be used to change the terminator to
  390. a zero byte. If a line number is also being output, it follows the file name.
  391. This option overrides any previous \fB-H\fP, \fB-L\fP, or \fB-l\fP options.
  392. .TP
  393. \fB--heap-limit\fP=\fInumber\fP
  394. See \fB--match-limit\fP below.
  395. .TP
  396. \fB--help\fP
  397. Output a help message, giving brief details of the command options and file
  398. type support, and then exit. Anything else on the command line is
  399. ignored.
  400. .TP
  401. \fB-I\fP
  402. Ignore binary files. This is equivalent to
  403. \fB--binary-files\fP=\fIwithout-match\fP.
  404. .TP
  405. \fB-i\fP, \fB--ignore-case\fP
  406. Ignore upper/lower case distinctions when pattern matching. This applies when
  407. matching path names for inclusion or exclusion as well as when matching lines
  408. in files.
  409. .TP
  410. \fB--include\fP=\fIpattern\fP
  411. If any \fB--include\fP patterns are specified, the only files that are
  412. processed are those whose names match one of the patterns and do not match an
  413. \fB--exclude\fP pattern. This option does not affect directories, but it
  414. applies to all files, whether listed on the command line, obtained from
  415. \fB--file-list\fP, or by scanning a directory. The pattern is a PCRE2 regular
  416. expression, and is matched against the final component of the file name, not
  417. the entire path. The \fB-F\fP, \fB-w\fP, and \fB-x\fP options do not apply to
  418. this pattern. The option may be given any number of times. If a file name
  419. matches both an \fB--include\fP and an \fB--exclude\fP pattern, it is excluded.
  420. There is no short form for this option.
  421. .TP
  422. \fB--include-from=\fP\fIfilename\fP
  423. Treat each non-empty line of the file as the data for an \fB--include\fP
  424. option. What constitutes a newline for this purpose is the operating system's
  425. default. The \fB--newline\fP option has no effect on this option. This option
  426. may be given any number of times; all the files are read.
  427. .TP
  428. \fB--include-dir\fP=\fIpattern\fP
  429. If any \fB--include-dir\fP patterns are specified, the only directories that
  430. are processed are those whose names match one of the patterns and do not match
  431. an \fB--exclude-dir\fP pattern. This applies to all directories, whether listed
  432. on the command line, obtained from \fB--file-list\fP, or by scanning a parent
  433. directory. The pattern is a PCRE2 regular expression, and is matched against
  434. the final component of the directory name, not the entire path. The \fB-F\fP,
  435. \fB-w\fP, and \fB-x\fP options do not apply to this pattern. The option may be
  436. given any number of times. If a directory matches both \fB--include-dir\fP and
  437. \fB--exclude-dir\fP, it is excluded. There is no short form for this option.
  438. .TP
  439. \fB-L\fP, \fB--files-without-match\fP
  440. Instead of outputting lines from the files, just output the names of the files
  441. that do not contain any lines that would have been output. Each file name is
  442. output once, on a separate line by default, but if the \fB-Z\fP option is set,
  443. they are separated by zero bytes instead of newlines. This option overrides any
  444. previous \fB-H\fP, \fB-h\fP, or \fB-l\fP options.
  445. .TP
  446. \fB-l\fP, \fB--files-with-matches\fP
  447. Instead of outputting lines from the files, just output the names of the files
  448. containing lines that would have been output. Each file name is output once, on
  449. a separate line, but if the \fB-Z\fP option is set, they are separated by zero
  450. bytes instead of newlines. Searching normally stops as soon as a matching line
  451. is found in a file. However, if the \fB-c\fP (count) option is also used,
  452. matching continues in order to obtain the correct count, and those files that
  453. have at least one match are listed along with their counts. Using this option
  454. with \fB-c\fP is a way of suppressing the listing of files with no matches that
  455. occurs with \fB-c\fP on its own. This option overrides any previous \fB-H\fP,
  456. \fB-h\fP, or \fB-L\fP options.
  457. .TP
  458. \fB--label\fP=\fIname\fP
  459. This option supplies a name to be used for the standard input when file names
  460. are being output. If not supplied, "(standard input)" is used. There is no
  461. short form for this option.
  462. .TP
  463. \fB--line-buffered\fP
  464. When this option is given, non-compressed input is read and processed line by
  465. line, and the output is flushed after each write. By default, input is read in
  466. large chunks, unless \fBpcre2grep\fP can determine that it is reading from a
  467. terminal, which is currently possible only in Unix-like environments or
  468. Windows. Output to terminal is normally automatically flushed by the operating
  469. system. This option can be useful when the input or output is attached to a
  470. pipe and you do not want \fBpcre2grep\fP to buffer up large amounts of data.
  471. However, its use will affect performance, and the \fB-M\fP (multiline) option
  472. ceases to work. When input is from a compressed .gz or .bz2 file,
  473. \fB--line-buffered\fP is ignored.
  474. .TP
  475. \fB--line-offsets\fP
  476. Instead of showing lines or parts of lines that match, show each match as a
  477. line number, the offset from the start of the line, and a length. The line
  478. number is terminated by a colon (as usual; see the \fB-n\fP option), and the
  479. offset and length are separated by a comma. In this mode, \fB--colour\fP has no
  480. effect, and no context is shown. That is, the \fB-A\fP, \fB-B\fP, and \fB-C\fP
  481. options are ignored. If there is more than one match in a line, each of them is
  482. shown separately. This option is mutually exclusive with \fB--output\fP,
  483. \fB--file-offsets\fP, and \fB--only-matching\fP.
  484. .TP
  485. \fB--locale\fP=\fIlocale-name\fP
  486. This option specifies a locale to be used for pattern matching. It overrides
  487. the value in the \fBLC_ALL\fP or \fBLC_CTYPE\fP environment variables. If no
  488. locale is specified, the PCRE2 library's default (usually the "C" locale) is
  489. used. There is no short form for this option.
  490. .TP
  491. \fB-M\fP, \fB--multiline\fP
  492. Allow patterns to match more than one line. When this option is set, the PCRE2
  493. library is called in "multiline" mode, and a match is allowed to continue past
  494. the end of the initial line and onto one or more subsequent lines.
  495. .sp
  496. Patterns used with \fB-M\fP may usefully contain literal newline characters and
  497. internal occurrences of ^ and $ characters, because in multiline mode these can
  498. match at internal newlines. Because \fBpcre2grep\fP is scanning multiple lines,
  499. the \eZ and \ez assertions match only at the end of the last line in the file.
  500. The \eA assertion matches at the start of the first line of a match. This can
  501. be any line in the file; it is not anchored to the first line.
  502. .sp
  503. The output for a successful match may consist of more than one line. The first
  504. line is the line in which the match started, and the last line is the line in
  505. which the match ended. If the matched string ends with a newline sequence, the
  506. output ends at the end of that line. If \fB-v\fP is set, none of the lines in a
  507. multi-line match are output. Once a match has been handled, scanning restarts
  508. at the beginning of the line after the one in which the match ended.
  509. .sp
  510. The newline sequence that separates multiple lines must be matched as part of
  511. the pattern. For example, to find the phrase "regular expression" in a file
  512. where "regular" might be at the end of a line and "expression" at the start of
  513. the next line, you could use this command:
  514. .sp
  515. pcre2grep -M 'regular\es+expression' <file>
  516. .sp
  517. The \es escape sequence matches any white space character, including newlines,
  518. and is followed by + so as to match trailing white space on the first line as
  519. well as possibly handling a two-character newline sequence.
  520. .sp
  521. There is a limit to the number of lines that can be matched, imposed by the way
  522. that \fBpcre2grep\fP buffers the input file as it scans it. With a sufficiently
  523. large processing buffer, this should not be a problem.
  524. .sp
  525. The \fB-M\fP option does not work when input is read line by line (see
  526. \fB--line-buffered\fP.)
  527. .TP
  528. \fB-m\fP \fInumber\fP, \fB--max-count\fP=\fInumber\fP
  529. Stop processing after finding \fInumber\fP matching lines, or non-matching
  530. lines if \fB-v\fP is also set. Any trailing context lines are output after the
  531. final match. In multiline mode, each multiline match counts as just one line
  532. for this purpose. If this limit is reached when reading the standard input from
  533. a regular file, the file is left positioned just after the last matching line.
  534. If \fB-c\fP is also set, the count that is output is never greater than
  535. \fInumber\fP. This option has no effect if used with \fB-L\fP, \fB-l\fP, or
  536. \fB-q\fP, or when just checking for a match in a binary file.
  537. .TP
  538. \fB--match-limit\fP=\fInumber\fP
  539. Processing some regular expression patterns may take a very long time to search
  540. for all possible matching strings. Others may require a very large amount of
  541. memory. There are three options that set resource limits for matching.
  542. .sp
  543. The \fB--match-limit\fP option provides a means of limiting computing resource
  544. usage when processing patterns that are not going to match, but which have a
  545. very large number of possibilities in their search trees. The classic example
  546. is a pattern that uses nested unlimited repeats. Internally, PCRE2 has a
  547. counter that is incremented each time around its main processing loop. If the
  548. value set by \fB--match-limit\fP is reached, an error occurs.
  549. .sp
  550. The \fB--heap-limit\fP option specifies, as a number of kibibytes (units of
  551. 1024 bytes), the maximum amount of heap memory that may be used for matching.
  552. .sp
  553. The \fB--depth-limit\fP option limits the depth of nested backtracking points,
  554. which indirectly limits the amount of memory that is used. The amount of memory
  555. needed for each backtracking point depends on the number of capturing
  556. parentheses in the pattern, so the amount of memory that is used before this
  557. limit acts varies from pattern to pattern. This limit is of use only if it is
  558. set smaller than \fB--match-limit\fP.
  559. .sp
  560. There are no short forms for these options. The default limits can be set
  561. when the PCRE2 library is compiled; if they are not specified, the defaults
  562. are very large and so effectively unlimited.
  563. .TP
  564. \fB--max-buffer-size\fP=\fInumber\fP
  565. This limits the expansion of the processing buffer, whose initial size can be
  566. set by \fB--buffer-size\fP. The maximum buffer size is silently forced to be no
  567. smaller than the starting buffer size.
  568. .TP
  569. \fB-N\fP \fInewline-type\fP, \fB--newline\fP=\fInewline-type\fP
  570. Six different conventions for indicating the ends of lines in scanned files are
  571. supported. For example:
  572. .sp
  573. pcre2grep -N CRLF 'some pattern' <file>
  574. .sp
  575. The newline type may be specified in upper, lower, or mixed case. If the
  576. newline type is NUL, lines are separated by binary zero characters. The other
  577. types are the single-character sequences CR (carriage return) and LF
  578. (linefeed), the two-character sequence CRLF, an "anycrlf" type, which
  579. recognizes any of the preceding three types, and an "any" type, for which any
  580. Unicode line ending sequence is assumed to end a line. The Unicode sequences
  581. are the three just mentioned, plus VT (vertical tab, U+000B), FF (form feed,
  582. U+000C), NEL (next line, U+0085), LS (line separator, U+2028), and PS
  583. (paragraph separator, U+2029).
  584. .sp
  585. When the PCRE2 library is built, a default line-ending sequence is specified.
  586. This is normally the standard sequence for the operating system. Unless
  587. otherwise specified by this option, \fBpcre2grep\fP uses the library's default.
  588. .sp
  589. This option makes it possible to use \fBpcre2grep\fP to scan files that have
  590. come from other environments without having to modify their line endings. If
  591. the data that is being scanned does not agree with the convention set by this
  592. option, \fBpcre2grep\fP may behave in strange ways. Note that this option does
  593. not apply to files specified by the \fB-f\fP, \fB--exclude-from\fP, or
  594. \fB--include-from\fP options, which are expected to use the operating system's
  595. standard newline sequence.
  596. .TP
  597. \fB-n\fP, \fB--line-number\fP
  598. Precede each output line by its line number in the file, followed by a colon
  599. for matching lines or a hyphen for context lines. If the file name is also
  600. being output, it precedes the line number. When the \fB-M\fP option causes a
  601. pattern to match more than one line, only the first is preceded by its line
  602. number. This option is forced if \fB--line-offsets\fP is used.
  603. .TP
  604. \fB--no-group-separator\fP
  605. Do not output a separator between groups of lines when \fB-A\fP, \fB-B\fP, or
  606. \fB-C\fP is in use. The default is to output a line containing two hyphens. See
  607. also \fB--group-separator\fP.
  608. .TP
  609. \fB--no-jit\fP
  610. If the PCRE2 library is built with support for just-in-time compiling (which
  611. speeds up matching), \fBpcre2grep\fP automatically makes use of this, unless it
  612. was explicitly disabled at build time. This option can be used to disable the
  613. use of JIT at run time. It is provided for testing and working around problems.
  614. It should never be needed in normal use.
  615. .TP
  616. \fB-O\fP \fItext\fP, \fB--output\fP=\fItext\fP
  617. When there is a match, instead of outputting the line that matched, output just
  618. the text specified in this option, followed by an operating-system standard
  619. newline. In this mode, \fB--colour\fP has no effect, and no context is shown.
  620. That is, the \fB-A\fP, \fB-B\fP, and \fB-C\fP options are ignored. The
  621. \fB--newline\fP option has no effect on this option, which is mutually
  622. exclusive with \fB--only-matching\fP, \fB--file-offsets\fP, and
  623. \fB--line-offsets\fP. However, like \fB--only-matching\fP, if there is more
  624. than one match in a line, each of them causes a line of output.
  625. .sp
  626. Escape sequences starting with a dollar character may be used to insert the
  627. contents of the matched part of the line and/or captured substrings into the
  628. text.
  629. .sp
  630. $<digits> or ${<digits>} is replaced by the captured substring of the given
  631. decimal number; zero substitutes the whole match. If the number is greater than
  632. the number of capturing substrings, or if the capture is unset, the replacement
  633. is empty.
  634. .sp
  635. $a is replaced by bell; $b by backspace; $e by escape; $f by form feed; $n by
  636. newline; $r by carriage return; $t by tab; $v by vertical tab.
  637. .sp
  638. $o<digits> or $o{<digits>} is replaced by the character whose code point is the
  639. given octal number. In the first form, up to three octal digits are processed.
  640. When more digits are needed in Unicode mode to specify a wide character, the
  641. second form must be used.
  642. .sp
  643. $x<digits> or $x{<digits>} is replaced by the character represented by the
  644. given hexadecimal number. In the first form, up to two hexadecimal digits are
  645. processed. When more digits are needed in Unicode mode to specify a wide
  646. character, the second form must be used.
  647. .sp
  648. Any other character is substituted by itself. In particular, $$ is replaced by
  649. a single dollar.
  650. .TP
  651. \fB-o\fP, \fB--only-matching\fP
  652. Show only the part of the line that matched a pattern instead of the whole
  653. line. In this mode, no context is shown. That is, the \fB-A\fP, \fB-B\fP, and
  654. \fB-C\fP options are ignored. If there is more than one match in a line, each
  655. of them is shown separately, on a separate line of output. If \fB-o\fP is
  656. combined with \fB-v\fP (invert the sense of the match to find non-matching
  657. lines), no output is generated, but the return code is set appropriately. If
  658. the matched portion of the line is empty, nothing is output unless the file
  659. name or line number are being printed, in which case they are shown on an
  660. otherwise empty line. This option is mutually exclusive with \fB--output\fP,
  661. \fB--file-offsets\fP and \fB--line-offsets\fP.
  662. .TP
  663. \fB-o\fP\fInumber\fP, \fB--only-matching\fP=\fInumber\fP
  664. Show only the part of the line that matched the capturing parentheses of the
  665. given number. Up to 50 capturing parentheses are supported by default. This
  666. limit can be changed via the \fB--om-capture\fP option. A pattern may contain
  667. any number of capturing parentheses, but only those whose number is within the
  668. limit can be accessed by \fB-o\fP. An error occurs if the number specified by
  669. \fB-o\fP is greater than the limit.
  670. .sp
  671. -o0 is the same as \fB-o\fP without a number. Because these options can be
  672. given without an argument (see above), if an argument is present, it must be
  673. given in the same shell item, for example, -o3 or --only-matching=2. The
  674. comments given for the non-argument case above also apply to this option. If
  675. the specified capturing parentheses do not exist in the pattern, or were not
  676. set in the match, nothing is output unless the file name or line number are
  677. being output.
  678. .sp
  679. If this option is given multiple times, multiple substrings are output for each
  680. match, in the order the options are given, and all on one line. For example,
  681. -o3 -o1 -o3 causes the substrings matched by capturing parentheses 3 and 1 and
  682. then 3 again to be output. By default, there is no separator (but see the next
  683. but one option).
  684. .TP
  685. \fB--om-capture\fP=\fInumber\fP
  686. Set the number of capturing parentheses that can be accessed by \fB-o\fP. The
  687. default is 50.
  688. .TP
  689. \fB--om-separator\fP=\fItext\fP
  690. Specify a separating string for multiple occurrences of \fB-o\fP. The default
  691. is an empty string. Separating strings are never coloured.
  692. .TP
  693. \fB-P\fP, \fB--no-ucp\fP
  694. Starting from release 10.43, when UTF/Unicode mode is specified with \fB-u\fP
  695. or \fB-U\fP, the PCRE2_UCP option is used by default. This means that the
  696. POSIX classes in patterns match more than just ASCII characters. For example,
  697. [:digit:] matches any Unicode decimal digit. The \fB--no-ucp\fP option
  698. suppresses PCRE2_UCP, thus restricting the POSIX classes to ASCII characters,
  699. as was the case in earlier releases. Note that there are now more fine-grained
  700. option settings within patterns that affect individual classes. For example,
  701. when in UCP mode, the sequence (?aP) restricts [:word:] to ASCII letters, while
  702. allowing \ew to match Unicode letters and digits.
  703. .TP
  704. \fB-q\fP, \fB--quiet\fP
  705. Work quietly, that is, display nothing except error messages. The exit
  706. status indicates whether or not any matches were found.
  707. .TP
  708. \fB-r\fP, \fB--recursive\fP
  709. If any given path is a directory, recursively scan the files it contains,
  710. taking note of any \fB--include\fP and \fB--exclude\fP settings. By default, a
  711. directory is read as a normal file; in some operating systems this gives an
  712. immediate end-of-file. This option is a shorthand for setting the \fB-d\fP
  713. option to "recurse".
  714. .TP
  715. \fB--recursion-limit\fP=\fInumber\fP
  716. This is an obsolete synonym for \fB--depth-limit\fP. See \fB--match-limit\fP
  717. above for details.
  718. .TP
  719. \fB-s\fP, \fB--no-messages\fP
  720. Suppress error messages about non-existent or unreadable files. Such files are
  721. quietly skipped. However, the return code is still 2, even if matches were
  722. found in other files.
  723. .TP
  724. \fB-t\fP, \fB--total-count\fP
  725. This option is useful when scanning more than one file. If used on its own,
  726. \fB-t\fP suppresses all output except for a grand total number of matching
  727. lines (or non-matching lines if \fB-v\fP is used) in all the files. If \fB-t\fP
  728. is used with \fB-c\fP, a grand total is output except when the previous output
  729. is just one line. In other words, it is not output when just one file's count
  730. is listed. If file names are being output, the grand total is preceded by
  731. "TOTAL:". Otherwise, it appears as just another number. The \fB-t\fP option is
  732. ignored when used with \fB-L\fP (list files without matches), because the grand
  733. total would always be zero.
  734. .TP
  735. \fB-u\fP, \fB--utf\fP
  736. Operate in UTF/Unicode mode. This option is available only if PCRE2 has been
  737. compiled with UTF-8 support. All patterns (including those for any
  738. \fB--exclude\fP and \fB--include\fP options) and all lines that are scanned
  739. must be valid strings of UTF-8 characters. If an invalid UTF-8 string is
  740. encountered, an error occurs.
  741. .TP
  742. \fB-U\fP, \fB--utf-allow-invalid\fP
  743. As \fB--utf\fP, but in addition subject lines may contain invalid UTF-8 code
  744. unit sequences. These can never form part of any pattern match. Patterns
  745. themselves, however, must still be valid UTF-8 strings. This facility allows
  746. valid UTF-8 strings to be sought within arbitrary byte sequences in executable
  747. or other binary files. For more details about matching in non-valid UTF-8
  748. strings, see the
  749. .\" HREF
  750. \fBpcre2unicode\fP(3)
  751. .\"
  752. documentation.
  753. .TP
  754. \fB-V\fP, \fB--version\fP
  755. Write the version numbers of \fBpcre2grep\fP and the PCRE2 library to the
  756. standard output and then exit. Anything else on the command line is
  757. ignored.
  758. .TP
  759. \fB-v\fP, \fB--invert-match\fP
  760. Invert the sense of the match, so that lines which do \fInot\fP match any of
  761. the patterns are the ones that are found. When this option is set, options such
  762. as \fB--only-matching\fP and \fB--output\fP, which specify parts of a match
  763. that are to be output, are ignored.
  764. .TP
  765. \fB-w\fP, \fB--word-regex\fP, \fB--word-regexp\fP
  766. Force the patterns only to match "words". That is, there must be a word
  767. boundary at the start and end of each matched string. This is equivalent to
  768. having "\eb(?:" at the start of each pattern, and ")\eb" at the end. This
  769. option applies only to the patterns that are matched against the contents of
  770. files; it does not apply to patterns specified by any of the \fB--include\fP or
  771. \fB--exclude\fP options.
  772. .TP
  773. \fB-x\fP, \fB--line-regex\fP, \fB--line-regexp\fP
  774. Force the patterns to start matching only at the beginnings of lines, and in
  775. addition, require them to match entire lines. In multiline mode the match may
  776. be more than one line. This is equivalent to having "^(?:" at the start of each
  777. pattern and ")$" at the end. This option applies only to the patterns that are
  778. matched against the contents of files; it does not apply to patterns specified
  779. by any of the \fB--include\fP or \fB--exclude\fP options.
  780. .TP
  781. \fB-Z\fP, \fB--null\fP
  782. Terminate files names in the regular output with a zero byte (the NUL
  783. character) instead of what would normally appear. This is useful when file
  784. names contain unusual characters such as colons, hyphens, or even newlines. The
  785. option does not apply to file names in error messages.
  786. .
  787. .
  788. .SH "ENVIRONMENT VARIABLES"
  789. .rs
  790. .sp
  791. The environment variables \fBLC_ALL\fP and \fBLC_CTYPE\fP are examined, in that
  792. order, for a locale. The first one that is set is used. This can be overridden
  793. by the \fB--locale\fP option. If no locale is set, the PCRE2 library's default
  794. (usually the "C" locale) is used.
  795. .
  796. .
  797. .SH "NEWLINES"
  798. .rs
  799. .sp
  800. The \fB-N\fP (\fB--newline\fP) option allows \fBpcre2grep\fP to scan files with
  801. newline conventions that differ from the default. This option affects only the
  802. way scanned files are processed. It does not affect the interpretation of files
  803. specified by the \fB-f\fP, \fB--file-list\fP, \fB--exclude-from\fP, or
  804. \fB--include-from\fP options.
  805. .P
  806. Any parts of the scanned input files that are written to the standard output
  807. are copied with whatever newline sequences they have in the input. However, if
  808. the final line of a file is output, and it does not end with a newline
  809. sequence, a newline sequence is added. If the newline setting is CR, LF, CRLF
  810. or NUL, that line ending is output; for the other settings (ANYCRLF or ANY) a
  811. single NL is used.
  812. .P
  813. The newline setting does not affect the way in which \fBpcre2grep\fP writes
  814. newlines in informational messages to the standard output and error streams.
  815. Under Windows, the standard output is set to be binary, so that "\er\en" at the
  816. ends of output lines that are copied from the input is not converted to
  817. "\er\er\en" by the C I/O library. This means that any messages written to the
  818. standard output must end with "\er\en". For all other operating systems, and
  819. for all messages to the standard error stream, "\en" is used.
  820. .
  821. .
  822. .SH "OPTIONS COMPATIBILITY WITH GNU GREP"
  823. .rs
  824. .sp
  825. Many of the short and long forms of \fBpcre2grep\fP's options are the same as
  826. in the GNU \fBgrep\fP program. Any long option of the form \fB--xxx-regexp\fP
  827. (GNU terminology) is also available as \fB--xxx-regex\fP (PCRE2 terminology).
  828. However, the \fB--case-restrict\fP, \fB--depth-limit\fP, \fB-E\fP,
  829. \fB--file-list\fP, \fB--file-offsets\fP, \fB--heap-limit\fP,
  830. \fB--include-dir\fP, \fB--line-offsets\fP, \fB--locale\fP, \fB--match-limit\fP,
  831. \fB-M\fP, \fB--multiline\fP, \fB-N\fP, \fB--newline\fP, \fB--no-ucp\fP,
  832. \fB--om-separator\fP, \fB--output\fP, \fB-P\fP, \fB-u\fP, \fB--utf\fP,
  833. \fB-U\fP, and \fB--utf-allow-invalid\fP options are specific to
  834. \fBpcre2grep\fP, as is the use of the \fB--only-matching\fP option with a
  835. capturing parentheses number.
  836. .P
  837. Although most of the common options work the same way, a few are different in
  838. \fBpcre2grep\fP. For example, the \fB--include\fP option's argument is a glob
  839. for GNU \fBgrep\fP, but in \fBpcre2grep\fP it is a regular expression to which
  840. the \fB-i\fP option applies. If both the \fB-c\fP and \fB-l\fP options are
  841. given, GNU grep lists only file names, without counts, but \fBpcre2grep\fP
  842. gives the counts as well.
  843. .
  844. .
  845. .SH "OPTIONS WITH DATA"
  846. .rs
  847. .sp
  848. There are four different ways in which an option with data can be specified.
  849. If a short form option is used, the data may follow immediately, or (with one
  850. exception) in the next command line item. For example:
  851. .sp
  852. -f/some/file
  853. -f /some/file
  854. .sp
  855. The exception is the \fB-o\fP option, which may appear with or without data.
  856. Because of this, if data is present, it must follow immediately in the same
  857. item, for example -o3.
  858. .P
  859. If a long form option is used, the data may appear in the same command line
  860. item, separated by an equals character, or (with two exceptions) it may appear
  861. in the next command line item. For example:
  862. .sp
  863. --file=/some/file
  864. --file /some/file
  865. .sp
  866. Note, however, that if you want to supply a file name beginning with ~ as data
  867. in a shell command, and have the shell expand ~ to a home directory, you must
  868. separate the file name from the option, because the shell does not treat ~
  869. specially unless it is at the start of an item.
  870. .P
  871. The exceptions to the above are the \fB--colour\fP (or \fB--color\fP) and
  872. \fB--only-matching\fP options, for which the data is optional. If one of these
  873. options does have data, it must be given in the first form, using an equals
  874. character. Otherwise \fBpcre2grep\fP will assume that it has no data.
  875. .
  876. .
  877. .SH "USING PCRE2'S CALLOUT FACILITY"
  878. .rs
  879. .sp
  880. \fBpcre2grep\fP has, by default, support for calling external programs or
  881. scripts or echoing specific strings during matching by making use of PCRE2's
  882. callout facility. However, this support can be completely or partially disabled
  883. when \fBpcre2grep\fP is built. You can find out whether your binary has support
  884. for callouts by running it with the \fB--help\fP option. If callout support is
  885. completely disabled, all callouts in patterns are ignored by \fBpcre2grep\fP.
  886. If the facility is partially disabled, calling external programs is not
  887. supported, and callouts that request it are ignored.
  888. .P
  889. A callout in a PCRE2 pattern is of the form (?C<arg>) where the argument is
  890. either a number or a quoted string (see the
  891. .\" HREF
  892. \fBpcre2callout\fP
  893. .\"
  894. documentation for details). Numbered callouts are ignored by \fBpcre2grep\fP;
  895. only callouts with string arguments are useful.
  896. .
  897. .
  898. .SS "Echoing a specific string"
  899. .rs
  900. .sp
  901. Starting the callout string with a pipe character invokes an echoing facility
  902. that avoids calling an external program or script. This facility is always
  903. available, provided that callouts were not completely disabled when
  904. \fBpcre2grep\fP was built. The rest of the callout string is processed as a
  905. zero-terminated string, which means it should not contain any internal binary
  906. zeros. It is written to the output, having first been passed through the same
  907. escape processing as text from the \fB--output\fP (\fB-O\fP) option (see
  908. above). However, $0 cannot be used to insert a matched substring because the
  909. match is still in progress. Instead, the single character '0' is inserted. Any
  910. syntax errors in the string (for example, a dollar not followed by another
  911. character) causes the callout to be ignored. No terminator is added to the
  912. output string, so if you want a newline, you must include it explicitly using
  913. the escape $n. For example:
  914. .sp
  915. pcre2grep '(.)(..(.))(?C"|[$1] [$2] [$3]$n")' <some file>
  916. .sp
  917. Matching continues normally after the string is output. If you want to see only
  918. the callout output but not any output from an actual match, you should end the
  919. pattern with (*FAIL).
  920. .
  921. .
  922. .SS "Calling external programs or scripts"
  923. .rs
  924. .sp
  925. This facility can be independently disabled when \fBpcre2grep\fP is built. It
  926. is supported for Windows, where a call to \fB_spawnvp()\fP is used, for VMS,
  927. where \fBlib$spawn()\fP is used, and for any Unix-like environment where
  928. \fBfork()\fP and \fBexecv()\fP are available.
  929. .P
  930. If the callout string does not start with a pipe (vertical bar) character, it
  931. is parsed into a list of substrings separated by pipe characters. The first
  932. substring must be an executable name, with the following substrings specifying
  933. arguments:
  934. .sp
  935. executable_name|arg1|arg2|...
  936. .sp
  937. Any substring (including the executable name) may contain escape sequences
  938. started by a dollar character. These are the same as for the \fB--output\fP
  939. (\fB-O\fP) option documented above, except that $0 cannot insert the matched
  940. string because the match is still in progress. Instead, the character '0'
  941. is inserted. If you need a literal dollar or pipe character in any
  942. substring, use $$ or $| respectively. Here is an example:
  943. .sp
  944. echo -e "abcde\en12345" | pcre2grep \e
  945. '(?x)(.)(..(.))
  946. (?C"/bin/echo|Arg1: [$1] [$2] [$3]|Arg2: $|${1}$| ($4)")()' -
  947. .sp
  948. Output:
  949. .sp
  950. Arg1: [a] [bcd] [d] Arg2: |a| ()
  951. abcde
  952. Arg1: [1] [234] [4] Arg2: |1| ()
  953. 12345
  954. .sp
  955. The parameters for the system call that is used to run the program or script
  956. are zero-terminated strings. This means that binary zero characters in the
  957. callout argument will cause premature termination of their substrings, and
  958. therefore should not be present. Any syntax errors in the string (for example,
  959. a dollar not followed by another character) causes the callout to be ignored.
  960. If running the program fails for any reason (including the non-existence of the
  961. executable), a local matching failure occurs and the matcher backtracks in the
  962. normal way.
  963. .
  964. .
  965. .SH "MATCHING ERRORS"
  966. .rs
  967. .sp
  968. It is possible to supply a regular expression that takes a very long time to
  969. fail to match certain lines. Such patterns normally involve nested indefinite
  970. repeats, for example: (a+)*\ed when matched against a line of a's with no final
  971. digit. The PCRE2 matching function has a resource limit that causes it to abort
  972. in these circumstances. If this happens, \fBpcre2grep\fP outputs an error
  973. message and the line that caused the problem to the standard error stream. If
  974. there are more than 20 such errors, \fBpcre2grep\fP gives up.
  975. .P
  976. The \fB--match-limit\fP option of \fBpcre2grep\fP can be used to set the
  977. overall resource limit. There are also other limits that affect the amount of
  978. memory used during matching; see the discussion of \fB--heap-limit\fP and
  979. \fB--depth-limit\fP above.
  980. .
  981. .
  982. .SH DIAGNOSTICS
  983. .rs
  984. .sp
  985. Exit status is 0 if any matches were found, 1 if no matches were found, and 2
  986. for syntax errors, overlong lines, non-existent or inaccessible files (even if
  987. matches were found in other files) or too many matching errors. Using the
  988. \fB-s\fP option to suppress error messages about inaccessible files does not
  989. affect the return code.
  990. .P
  991. When run under VMS, the return code is placed in the symbol PCRE2GREP_RC
  992. because VMS does not distinguish between exit(0) and exit(1).
  993. .
  994. .
  995. .SH "SEE ALSO"
  996. .rs
  997. .sp
  998. \fBpcre2pattern\fP(3), \fBpcre2syntax\fP(3), \fBpcre2callout\fP(3),
  999. \fBpcre2unicode\fP(3).
  1000. .
  1001. .
  1002. .SH AUTHOR
  1003. .rs
  1004. .sp
  1005. .nf
  1006. Philip Hazel
  1007. Retired from University Computing Service
  1008. Cambridge, England.
  1009. .fi
  1010. .
  1011. .
  1012. .SH REVISION
  1013. .rs
  1014. .sp
  1015. .nf
  1016. Last updated: 22 December 2023
  1017. Copyright (c) 1997-2023 University of Cambridge.
  1018. .fi