grep 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. .TH GREP 1
  2. .SH NAME
  3. grep \- search a file for a pattern
  4. .SH SYNOPSIS
  5. .B grep
  6. [
  7. .B -bchiLlnsv
  8. ]
  9. [
  10. .B -e
  11. ]
  12. .I pattern
  13. |
  14. .B -f
  15. .I patternfile
  16. [
  17. .I file ...
  18. ]
  19. .SH DESCRIPTION
  20. .I Grep\^
  21. searches the input
  22. .I files\^
  23. (standard input default)
  24. for lines that match the
  25. .IR pattern ,
  26. a regular expression as defined in
  27. .IR regexp (6)
  28. with the addition of a newline character as an alternative
  29. (substitute for
  30. .BR | )
  31. with lowest precedence.
  32. Normally, each line matching the pattern is `selected',
  33. and each selected line is copied to the standard output.
  34. The options are
  35. .TP
  36. .B -c
  37. Print only a count of matching lines.
  38. .PD 0
  39. .TP
  40. .B -h
  41. Do not print file name tags (headers) with output lines.
  42. .TP
  43. .B -e
  44. The following argument is taken as a
  45. .IR pattern .
  46. This option makes it easy to specify patterns that
  47. might confuse argument parsing, such as
  48. .BR -n .
  49. .TP
  50. .B -i
  51. Ignore alphabetic case distinctions. The implementation
  52. folds into lower case all letters in the pattern and input before
  53. interpretation. Matched lines are printed in their original form.
  54. .TP
  55. .B -l
  56. (ell) Print the names of files with selected lines; don't print the lines.
  57. .TP
  58. .B -L
  59. Print the names of files with no selected lines;
  60. the converse of
  61. .BR -l .
  62. .TP
  63. .B -n
  64. Mark each printed line with its line number counted in its file.
  65. .TP
  66. .B -s
  67. Produce no output, but return status.
  68. .TP
  69. .B -v
  70. Reverse: print lines that do not match the pattern.
  71. .TP
  72. .B -f
  73. The pattern argument is the name of a file containing regular
  74. expressions one per line.
  75. .TP
  76. .B -b
  77. Don't buffer the output: write each output line as soon as it is discovered.
  78. .PD
  79. .PP
  80. Output lines are tagged by file name when there is more than one
  81. input file.
  82. (To force this tagging, include
  83. .B /dev/null
  84. as a file name argument.)
  85. .PP
  86. Care should be taken when
  87. using the shell metacharacters
  88. .B $*[^|()=\e
  89. and newline
  90. in
  91. .IR pattern ;
  92. it is safest to enclose the
  93. entire expression
  94. in single quotes
  95. .BR \&\|' \|.\|.\|.\| ' .
  96. An expression starting with '*'
  97. will treat the rest of the expression
  98. as literal characters.
  99. .SH SOURCE
  100. .B /sys/src/cmd/grep
  101. .SH SEE ALSO
  102. .IR ed (1),
  103. .IR awk (1),
  104. .IR sed (1),
  105. .IR sam (1),
  106. .IR regexp (6)
  107. .SH DIAGNOSTICS
  108. Exit status is null if any lines are selected,
  109. or non-null when no lines are selected or an error occurs.