pcregrep.1 35 KB

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