pcregrep.txt 41 KB

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