home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 September / Simtel20_Sept92.cdr / utils / grep.doc < prev    next >
Text File  |  1992-08-01  |  6KB  |  127 lines

  1.  
  2. grep, egrep - print lines matching a regular expression
  3.  
  4. searches the files listed in the arguments (or standard input if no files
  5. are given) for all lines that contain a match for the given If any lines
  6. match, they are printed.  Also, if any matches were found, will exit with a
  7. status of 0, but if no matches were found it will exit with a status of 1.
  8. This is useful for building shell scripts that use as a condition for, for
  9. example, the statement.  When invoked as the syntax of the is slightly
  10. different; See below.
  11.  
  12. (grep)    (egrep)   (explanation)
  13.  
  14. c         c         a single  (non-meta)  character  matches itself.
  15.  
  16. .         .         matches any single character except newline.
  17.  
  18. \?        ?         postfix  operator;  preceeding  item  is optional.
  19.  
  20. *         *         postfix operator; preceeding item  0  or more times.
  21.  
  22. \+        +         postfix operator; preceeding item  1  or more times.
  23.  
  24. \|        |         infix operator; matches either argument.
  25.  
  26. ^         ^         matches the empty string at  the  beginning of a line.
  27.  
  28. $         $         matches the empty string at the end of a line.
  29.  
  30. \<        \<        matches the empty string at  the  beginning of a word.
  31.  
  32. \>        \>        matches the empty string at the end of a word.
  33.  
  34. [chars]   [chars]   match any character in the given  class;
  35. if the first character after [ is ^, match any character not
  36. in the given class; a range of characters may  be  specified
  37. by  first-last; for example, \W (below) is equivalent to the
  38. class [^A-Za-z0-9]
  39.  
  40. \( \)     ( )       parentheses are used to override  opera-
  41. tor precedence.
  42.  
  43. \digit    \digit    \n matches a repeat of the text  matched
  44. earlier  in  the  regexp by the subexpression inside the nth
  45. opening parenthesis.
  46.  
  47. \         \         any special character may be preceded by
  48. a backslash to match it literally.
  49.  
  50. (the following are for compatibility with GNU Emacs)
  51.  
  52. \b        \b        matches the empty string at the edge  of
  53. a word.
  54.  
  55. \B        \B        matches the empty string if not  at  the
  56. edge of a word.
  57.  
  58. \w        \w        matches   word-constituent    characters
  59. (letters & digits).
  60.  
  61. \W        \W        matches characters that  are  not  word-
  62. constituent.   Operator precedence is (highest to lowest) ?,
  63. *, and +, concatenation, and  finally  |.   All  other  con-
  64. structs  are  syntactically  identical to normal characters.
  65. For the truly interested,  the  file  dfa.c  describes  (and
  66. implements)  the  exact  grammar  understood  by the parser.
  67. print <num> lines of context after every matching line print
  68. lines of context before every matching line print 2 lines of
  69. context on each side of every match print lines  of  context
  70. on  each side of every match print the version number on the
  71. diagnostic output print every match  preceded  by  its  byte
  72. offset print a total count of matching lines only search for
  73. useful if begins with - search for the expression  contained
  74. in don't display filenames on matches ignore case difference
  75. when comparing strings list files  containing  matches  only
  76. print  each  match  preceded by its line number run silently
  77. producing no output except error messages print  only  lines
  78. that  contain  no  matches  for  the <expr> print only lines
  79. where the match is a complete word print  only  lines  where
  80. the  match  is a whole line emacs(1), ed(1), sh(1), The fol-
  81. lowing  incompatibilities  with  UNIX  exist:  The  context-
  82. dependent  meaning  of  * is not quite the same (grep only).
  83. prints a byte offset instead of a block offset.   The  {m,n}
  84. construct  of  System V grep is not implemented.  GNU e?grep
  85. has been thoroughly debugged and tested  by  several  people
  86. over  a  period  of several months; we think it's a reliable
  87. beast or we wouldn't distribute it.  If by some fluke of the
  88. universe  you  discover  a  bug, send a detailed description
  89. (including options, regular expressions, and a  copy  of  an
  90. input    file    that    can    reproduce    it)    to   me,
  91. mike@wheaties.ai.mit.edu.   There  is  also   a   newsgroup,
  92. gnu.utils.bug,  for reporting FSF utility programs' bugs and
  93. fixes; but before reporting something as a bug,  please  try
  94. to  be  sure that it really is a bug, not a misunderstanding
  95. or a deliberate feature.  Also, include the  version  number
  96. of  the  utility program you are running in every bug report
  97. that you send in.  Please  do  not  send  anything  but  bug
  98. reports  to  this newsgroup.  GNU is free; anyone may redis-
  99. tribute copies of to anyone under the terms  stated  in  the
  100. GNU  General Public License, a copy of which may be found in
  101. each copy of See also the comment at the  beginning  of  the
  102. source  code  file  grep.c.   Copies of GNU may sometimes be
  103. received packaged with distributions of Unix systems, but it
  104. is never included in the scope of any license covering those
  105. systems.  Such inclusion violates the terms on which distri-
  106. bution  is  permitted.   In fact, the primary purpose of the
  107. General Public License is to prohibit anyone from  attaching
  108. any  other restrictions to redistribution of any of the Free
  109. Software Foundation programs.  Mike Haertel wrote the deter-
  110. ministic  regexp code and the bulk of the program.  James A.
  111. Woods is responsible for the hybridized search  strategy  of
  112. using  Boyer-Moore-Gosper  fixed-string  search  as a filter
  113. before calling the general  regexp  matcher.   Arthur  David
  114. Olson  contributed  code  that  finds  fixed strings for the
  115. aforementioned BMG search for  a  large  class  of  regexps.
  116. Richard  Stallman wrote the backtracking regexp matcher that
  117. is used for \digit backreferences, as  well  as  the  getopt
  118. that is provided for 4.2BSD sites.  The backtracking matcher
  119. was originally written for GNU Emacs.  D. A. Gwyn wrote  the
  120. C alloca emulation that is provided so System V machines can
  121. run this program.  (Alloca is used only by RMS' backtracking
  122. matcher,  and  then only rarely, so there is no loss if your
  123. machine doesn't have a "real" alloca.)  Scott  Anderson  and
  124. Henry  Spencer  designed  the  regression  tests used in the
  125. "regress" script.  Paul Placeway wrote the original  version
  126. of this manual page.
  127.