pcre2grep.1 48 KB

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