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