grep 2.2 KB

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