/[pcre]/code/trunk/doc/pcregrep.txt
ViewVC logotype

Diff of /code/trunk/doc/pcregrep.txt

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 344 by ph10, Mon Dec 17 14:46:11 2007 UTC revision 345 by ph10, Mon Apr 28 15:10:02 2008 UTC
# Line 173  OPTIONS Line 173  OPTIONS
173    
174         --exclude=pattern         --exclude=pattern
175                   When pcregrep is searching the files in a directory as a con-                   When pcregrep is searching the files in a directory as a con-
176                   sequence of the -r (recursive search) option, any files whose                   sequence of the -r (recursive  search)  option,  any  regular
177                   names  match  the pattern are excluded. The pattern is a PCRE                   files whose names match the pattern are excluded. Subdirecto-
178                   regular expression. If a file name matches both --include and                   ries are not excluded  by  this  option;  they  are  searched
179                   --exclude,  it  is  excluded. There is no short form for this                   recursively,  subject  to the --exclude_dir and --include_dir
180                     options. The pattern is a PCRE  regular  expression,  and  is
181                     matched against the final component of the file name (not the
182                     entire path). If a  file  name  matches  both  --include  and
183                     --exclude,  it  is excluded.  There is no short form for this
184                   option.                   option.
185    
186           --exclude_dir=pattern
187                     When pcregrep is searching the contents of a directory  as  a
188                     consequence  of  the -r (recursive search) option, any subdi-
189                     rectories whose names match the pattern are  excluded.  (Note
190                     that  the  --exclude  option does not affect subdirectories.)
191                     The pattern is a PCRE  regular  expression,  and  is  matched
192                     against  the  final  component  of  the  name (not the entire
193                     path). If a subdirectory name matches both --include_dir  and
194                     --exclude_dir,  it  is  excluded.  There is no short form for
195                     this option.
196    
197         -F, --fixed-strings         -F, --fixed-strings
198                   Interpret each pattern as a list of fixed strings,  separated                   Interpret each pattern as a list of fixed strings,  separated
199                   by  newlines,  instead  of  as  a  regular expression. The -w                   by  newlines,  instead  of  as  a  regular expression. The -w
# Line 235  OPTIONS Line 250  OPTIONS
250    
251         --include=pattern         --include=pattern
252                   When pcregrep is searching the files in a directory as a con-                   When pcregrep is searching the files in a directory as a con-
253                   sequence  of  the  -r  (recursive  search) option, only those                   sequence of the -r (recursive search) option, only those reg-
254                   files whose names match the pattern are included. The pattern                   ular files whose names match the pattern are included. Subdi-
255                   is  a  PCRE  regular  expression. If a file name matches both                   rectories  are always included and searched recursively, sub-
256                   --include and --exclude, it is excluded. There  is  no  short                   ject to the --include_dir and --exclude_dir options. The pat-
257                   form for this option.                   tern is a PCRE regular expression, and is matched against the
258                     final component of the file name (not the entire path). If  a
259                     file  name  matches  both  --include  and  --exclude,  it  is
260                     excluded. There is no short form for this option.
261    
262           --include_dir=pattern
263                     When pcregrep is searching the contents of a directory  as  a
264                     consequence  of  the -r (recursive search) option, only those
265                     subdirectories whose names match the  pattern  are  included.
266                     (Note  that  the --include option does not affect subdirecto-
267                     ries.) The pattern is  a  PCRE  regular  expression,  and  is
268                     matched  against  the  final  component  of the name (not the
269                     entire  path).  If   a   subdirectory   name   matches   both
270                     --include_dir  and --exclude_dir, it is excluded. There is no
271                     short form for this option.
272    
273         -L, --files-without-match         -L, --files-without-match
274                   Instead  of  outputting lines from the files, just output the                   Instead of outputting lines from the files, just  output  the
275                   names of the files that do not contain any lines  that  would                   names  of  the files that do not contain any lines that would
276                   have  been  output. Each file name is output once, on a sepa-                   have been output. Each file name is output once, on  a  sepa-
277                   rate line.                   rate line.
278    
279         -l, --files-with-matches         -l, --files-with-matches
280                   Instead of outputting lines from the files, just  output  the                   Instead  of  outputting lines from the files, just output the
281                   names of the files containing lines that would have been out-                   names of the files containing lines that would have been out-
282                   put. Each file name is  output  once,  on  a  separate  line.                   put.  Each  file  name  is  output  once, on a separate line.
283                   Searching  stops  as  soon  as  a matching line is found in a                   Searching stops as soon as a matching  line  is  found  in  a
284                   file.                   file.
285    
286         --label=name         --label=name
# Line 260  OPTIONS Line 289  OPTIONS
289                   input)" is used. There is no short form for this option.                   input)" is used. There is no short form for this option.
290    
291         --line-offsets         --line-offsets
292                   Instead of showing lines or parts of lines that  match,  show                   Instead  of  showing lines or parts of lines that match, show
293                   each match as a line number, the offset from the start of the                   each match as a line number, the offset from the start of the
294                   line, and a length. The line number is terminated by a  colon                   line,  and a length. The line number is terminated by a colon
295                   (as  usual; see the -n option), and the offset and length are                   (as usual; see the -n option), and the offset and length  are
296                   separated by a comma. In this  mode,  no  context  is  shown.                   separated  by  a  comma.  In  this mode, no context is shown.
297                   That  is, the -A, -B, and -C options are ignored. If there is                   That is, the -A, -B, and -C options are ignored. If there  is
298                   more than one match in a line, each of them  is  shown  sepa-                   more  than  one  match in a line, each of them is shown sepa-
299                   rately. This option is mutually exclusive with --file-offsets                   rately. This option is mutually exclusive with --file-offsets
300                   and --only-matching.                   and --only-matching.
301    
302         --locale=locale-name         --locale=locale-name
303                   This option specifies a locale to be used for pattern  match-                   This  option specifies a locale to be used for pattern match-
304                   ing.  It  overrides the value in the LC_ALL or LC_CTYPE envi-                   ing. It overrides the value in the LC_ALL or  LC_CTYPE  envi-
305                   ronment variables.  If  no  locale  is  specified,  the  PCRE                   ronment  variables.  If  no  locale  is  specified,  the PCRE
306                   library's  default (usually the "C" locale) is used. There is                   library's default (usually the "C" locale) is used. There  is
307                   no short form for this option.                   no short form for this option.
308    
309         -M, --multiline         -M, --multiline
310                   Allow patterns to match more than one line. When this  option                   Allow  patterns to match more than one line. When this option
311                   is given, patterns may usefully contain literal newline char-                   is given, patterns may usefully contain literal newline char-
312                   acters and internal occurrences of ^ and  $  characters.  The                   acters  and  internal  occurrences of ^ and $ characters. The
313                   output  for  any one match may consist of more than one line.                   output for any one match may consist of more than  one  line.
314                   When this option is set, the PCRE library is called in  "mul-                   When  this option is set, the PCRE library is called in "mul-
315                   tiline"  mode.   There is a limit to the number of lines that                   tiline" mode.  There is a limit to the number of  lines  that
316                   can be matched, imposed by the way that pcregrep buffers  the                   can  be matched, imposed by the way that pcregrep buffers the
317                   input  file as it scans it. However, pcregrep ensures that at                   input file as it scans it. However, pcregrep ensures that  at
318                   least 8K characters or the rest of the document (whichever is                   least 8K characters or the rest of the document (whichever is
319                   the  shorter)  are  available for forward matching, and simi-                   the shorter) are available for forward  matching,  and  simi-
320                   larly the previous 8K characters (or all the previous charac-                   larly the previous 8K characters (or all the previous charac-
321                   ters,  if  fewer  than 8K) are guaranteed to be available for                   ters, if fewer than 8K) are guaranteed to  be  available  for
322                   lookbehind assertions.                   lookbehind assertions.
323    
324         -N newline-type, --newline=newline-type         -N newline-type, --newline=newline-type
325                   The PCRE library  supports  five  different  conventions  for                   The  PCRE  library  supports  five  different conventions for
326                   indicating  the  ends of lines. They are the single-character                   indicating the ends of lines. They are  the  single-character
327                   sequences CR (carriage return) and LF  (linefeed),  the  two-                   sequences  CR  (carriage  return) and LF (linefeed), the two-
328                   character  sequence CRLF, an "anycrlf" convention, which rec-                   character sequence CRLF, an "anycrlf" convention, which  rec-
329                   ognizes any of the preceding three types, and an  "any"  con-                   ognizes  any  of the preceding three types, and an "any" con-
330                   vention, in which any Unicode line ending sequence is assumed                   vention, in which any Unicode line ending sequence is assumed
331                   to end a line. The Unicode sequences are the three just  men-                   to  end a line. The Unicode sequences are the three just men-
332                   tioned,   plus  VT  (vertical  tab,  U+000B),  FF  (formfeed,                   tioned,  plus  VT  (vertical  tab,  U+000B),  FF   (formfeed,
333                   U+000C),  NEL  (next  line,  U+0085),  LS  (line   separator,                   U+000C),   NEL  (next  line,  U+0085),  LS  (line  separator,
334                   U+2028), and PS (paragraph separator, U+2029).                   U+2028), and PS (paragraph separator, U+2029).
335    
336                   When  the  PCRE  library  is  built,  a  default  line-ending                   When  the  PCRE  library  is  built,  a  default  line-ending
337                   sequence  is  specified.   This  is  normally  the   standard                   sequence   is  specified.   This  is  normally  the  standard
338                   sequence for the operating system. Unless otherwise specified                   sequence for the operating system. Unless otherwise specified
339                   by this option, pcregrep uses  the  library's  default.   The                   by  this  option,  pcregrep  uses the library's default.  The
340                   possible values for this option are CR, LF, CRLF, ANYCRLF, or                   possible values for this option are CR, LF, CRLF, ANYCRLF, or
341                   ANY. This makes it possible to use  pcregrep  on  files  that                   ANY.  This  makes  it  possible to use pcregrep on files that
342                   have  come  from  other environments without having to modify                   have come from other environments without  having  to  modify
343                   their line endings. If the data that is  being  scanned  does                   their  line  endings.  If the data that is being scanned does
344                   not  agree  with  the convention set by this option, pcregrep                   not agree with the convention set by  this  option,  pcregrep
345                   may behave in strange ways.                   may behave in strange ways.
346    
347         -n, --line-number         -n, --line-number
348                   Precede each output line by its line number in the file, fol-                   Precede each output line by its line number in the file, fol-
349                   lowed  by  a colon and a space for matching lines or a hyphen                   lowed by a colon and a space for matching lines or  a  hyphen
350                   and a space for context lines. If the filename is also  being                   and  a space for context lines. If the filename is also being
351                   output, it precedes the line number. This option is forced if                   output, it precedes the line number. This option is forced if
352                   --line-offsets is used.                   --line-offsets is used.
353    
354         -o, --only-matching         -o, --only-matching
355                   Show only the part of the line that  matched  a  pattern.  In                   Show  only  the  part  of the line that matched a pattern. In
356                   this  mode,  no context is shown. That is, the -A, -B, and -C                   this mode, no context is shown. That is, the -A, -B,  and  -C
357                   options are ignored. If there is more than  one  match  in  a                   options  are  ignored.  If  there is more than one match in a
358                   line,  each  of  them  is shown separately. If -o is combined                   line, each of them is shown separately.  If  -o  is  combined
359                   with -v (invert the sense of the match to  find  non-matching                   with  -v  (invert the sense of the match to find non-matching
360                   lines),  no  output  is generated, but the return code is set                   lines), no output is generated, but the return  code  is  set
361                   appropriately. This option is mutually exclusive with --file-                   appropriately. This option is mutually exclusive with --file-
362                   offsets and --line-offsets.                   offsets and --line-offsets.
363    
364         -q, --quiet         -q, --quiet
365                   Work quietly, that is, display nothing except error messages.                   Work quietly, that is, display nothing except error messages.
366                   The exit status indicates whether or  not  any  matches  were                   The  exit  status  indicates  whether or not any matches were
367                   found.                   found.
368    
369         -r, --recursive         -r, --recursive
370                   If  any given path is a directory, recursively scan the files                   If any given path is a directory, recursively scan the  files
371                   it contains, taking note of any --include and --exclude  set-                   it  contains, taking note of any --include and --exclude set-
372                   tings.  By  default, a directory is read as a normal file; in                   tings. By default, a directory is read as a normal  file;  in
373                   some operating systems this gives an  immediate  end-of-file.                   some  operating  systems this gives an immediate end-of-file.
374                   This  option  is  a  shorthand  for  setting the -d option to                   This option is a shorthand  for  setting  the  -d  option  to
375                   "recurse".                   "recurse".
376    
377         -s, --no-messages         -s, --no-messages
378                   Suppress error  messages  about  non-existent  or  unreadable                   Suppress  error  messages  about  non-existent  or unreadable
379                   files.  Such  files  are quietly skipped. However, the return                   files. Such files are quietly skipped.  However,  the  return
380                   code is still 2, even if matches were found in other files.                   code is still 2, even if matches were found in other files.
381    
382         -u, --utf-8         -u, --utf-8
383                   Operate in UTF-8 mode. This option is available only if  PCRE                   Operate  in UTF-8 mode. This option is available only if PCRE
384                   has  been compiled with UTF-8 support. Both patterns and sub-                   has been compiled with UTF-8 support. Both patterns and  sub-
385                   ject lines must be valid strings of UTF-8 characters.                   ject lines must be valid strings of UTF-8 characters.
386    
387         -V, --version         -V, --version
388                   Write the version numbers of pcregrep and  the  PCRE  library                   Write  the  version  numbers of pcregrep and the PCRE library
389                   that is being used to the standard error stream.                   that is being used to the standard error stream.
390    
391         -v, --invert-match         -v, --invert-match
392                   Invert  the  sense  of  the match, so that lines which do not                   Invert the sense of the match, so that  lines  which  do  not
393                   match any of the patterns are the ones that are found.                   match any of the patterns are the ones that are found.
394    
395         -w, --word-regex, --word-regexp         -w, --word-regex, --word-regexp
# Line 368  OPTIONS Line 397  OPTIONS
397                   lent to having \b at the start and end of the pattern.                   lent to having \b at the start and end of the pattern.
398    
399         -x, --line-regex, --line-regexp         -x, --line-regex, --line-regexp
400                   Force  the  patterns to be anchored (each must start matching                   Force the patterns to be anchored (each must  start  matching
401                   at the beginning of a line) and in addition, require them  to                   at  the beginning of a line) and in addition, require them to
402                   match  entire  lines.  This  is  equivalent to having ^ and $                   match entire lines. This is equivalent  to  having  ^  and  $
403                   characters at the start and end of each alternative branch in                   characters at the start and end of each alternative branch in
404                   every pattern.                   every pattern.
405    
406    
407  ENVIRONMENT VARIABLES  ENVIRONMENT VARIABLES
408    
409         The  environment  variables  LC_ALL  and LC_CTYPE are examined, in that         The environment variables LC_ALL and LC_CTYPE  are  examined,  in  that
410         order, for a locale. The first one that is set is  used.  This  can  be         order,  for  a  locale.  The first one that is set is used. This can be
411         overridden  by  the  --locale  option.  If  no  locale is set, the PCRE         overridden by the --locale option.  If  no  locale  is  set,  the  PCRE
412         library's default (usually the "C" locale) is used.         library's default (usually the "C" locale) is used.
413    
414    
415  NEWLINES  NEWLINES
416    
417         The -N (--newline) option allows pcregrep to scan files with  different         The  -N (--newline) option allows pcregrep to scan files with different
418         newline  conventions  from  the  default.  However, the setting of this         newline conventions from the default.  However,  the  setting  of  this
419         option does not affect the way in which pcregrep writes information  to         option  does not affect the way in which pcregrep writes information to
420         the  standard  error  and  output streams. It uses the string "\n" in C         the standard error and output streams. It uses the  string  "\n"  in  C
421         printf() calls to indicate newlines, relying on the C  I/O  library  to         printf()  calls  to  indicate newlines, relying on the C I/O library to
422         convert  this  to  an  appropriate  sequence if the output is sent to a         convert this to an appropriate sequence if the  output  is  sent  to  a
423         file.         file.
424    
425    
426  OPTIONS COMPATIBILITY  OPTIONS COMPATIBILITY
427    
428         The majority of short and long forms of pcregrep's options are the same         The majority of short and long forms of pcregrep's options are the same
429         as  in  the  GNU grep program. Any long option of the form --xxx-regexp         as in the GNU grep program. Any long option of  the  form  --xxx-regexp
430         (GNU terminology) is also available as --xxx-regex (PCRE  terminology).         (GNU  terminology) is also available as --xxx-regex (PCRE terminology).
431         However,  the  --locale,  -M,  --multiline, -u, and --utf-8 options are         However, the --locale, -M, --multiline, -u,  and  --utf-8  options  are
432         specific to pcregrep.         specific to pcregrep.
433    
434    
435  OPTIONS WITH DATA  OPTIONS WITH DATA
436    
437         There are four different ways in which an option with data can be spec-         There are four different ways in which an option with data can be spec-
438         ified.   If  a  short  form option is used, the data may follow immedi-         ified.  If a short form option is used, the  data  may  follow  immedi-
439         ately, or in the next command line item. For example:         ately, or in the next command line item. For example:
440    
441           -f/some/file           -f/some/file
442           -f /some/file           -f /some/file
443    
444         If a long form option is used, the data may appear in the same  command         If  a long form option is used, the data may appear in the same command
445         line item, separated by an equals character, or (with one exception) it         line item, separated by an equals character, or (with one exception) it
446         may appear in the next command line item. For example:         may appear in the next command line item. For example:
447    
448           --file=/some/file           --file=/some/file
449           --file /some/file           --file /some/file
450    
451         Note, however, that if you want to supply a file name beginning with  ~         Note,  however, that if you want to supply a file name beginning with ~
452         as  data  in  a  shell  command,  and have the shell expand ~ to a home         as data in a shell command, and have the  shell  expand  ~  to  a  home
453         directory, you must separate the file name from the option, because the         directory, you must separate the file name from the option, because the
454         shell  does not treat ~ specially unless it is at the start of an item.         shell does not treat ~ specially unless it is at the start of an  item.
455    
456         The exception to the above is the --colour  (or  --color)  option,  for         The  exception  to  the  above is the --colour (or --color) option, for
457         which  the  data is optional. If this option does have data, it must be         which the data is optional. If this option does have data, it  must  be
458         given in the first form, using an equals character. Otherwise  it  will         given  in  the first form, using an equals character. Otherwise it will
459         be assumed that it has no data.         be assumed that it has no data.
460    
461    
462  MATCHING ERRORS  MATCHING ERRORS
463    
464         It  is  possible  to supply a regular expression that takes a very long         It is possible to supply a regular expression that takes  a  very  long
465         time to fail to match certain lines.  Such  patterns  normally  involve         time  to  fail  to  match certain lines. Such patterns normally involve
466         nested  indefinite repeats, for example: (a+)*\d when matched against a         nested indefinite repeats, for example: (a+)*\d when matched against  a
467         line of a's with no final digit.  The  PCRE  matching  function  has  a         line  of  a's  with  no  final  digit. The PCRE matching function has a
468         resource  limit that causes it to abort in these circumstances. If this         resource limit that causes it to abort in these circumstances. If  this
469         happens, pcregrep outputs an error message and the line that caused the         happens, pcregrep outputs an error message and the line that caused the
470         problem  to  the  standard error stream. If there are more than 20 such         problem to the standard error stream. If there are more  than  20  such
471         errors, pcregrep gives up.         errors, pcregrep gives up.
472    
473    
474  DIAGNOSTICS  DIAGNOSTICS
475    
476         Exit status is 0 if any matches were found, 1 if no matches were found,         Exit status is 0 if any matches were found, 1 if no matches were found,
477         and  2 for syntax errors and non-existent or inacessible files (even if         and 2 for syntax errors and non-existent or inacessible files (even  if
478         matches were found in other files) or too many matching  errors.  Using         matches  were  found in other files) or too many matching errors. Using
479         the  -s  option to suppress error messages about inaccessble files does         the -s option to suppress error messages about inaccessble  files  does
480         not affect the return code.         not affect the return code.
481    
482    
# Line 465  AUTHOR Line 494  AUTHOR
494    
495  REVISION  REVISION
496    
497         Last updated: 17 December 2007         Last updated: 08 March 2008
498         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2008 University of Cambridge.

Legend:
Removed from v.344  
changed lines
  Added in v.345

  ViewVC Help
Powered by ViewVC 1.1.5