1GREP(1)                     General Commands Manual                    GREP(1)
2
3
4

NAME

6       grep, egrep, fgrep - search a file for a pattern
7

SYNOPSIS

9       grep [ option ] ...  expression [ file ] ...
10
11       egrep [ option ] ...  [ expression ] [ file ] ...
12
13       fgrep [ option ] ...  [ strings ] [ file ]
14

DESCRIPTION

16       Commands  of  the  grep  family  search the input files (standard input
17       default) for lines matching a pattern.  Normally, each  line  found  is
18       copied  to  the  standard  output; unless the -h flag is used, the file
19       name is shown if there is more than one input file.
20
21       Grep patterns are limited regular expressions in the style of ed(1); it
22       uses  a  compact  nondeterministic  algorithm.  Egrep patterns are full
23       regular expressions; it uses a fast deterministic algorithm that  some‐
24       times needs exponential space.  Fgrep patterns are fixed strings; it is
25       fast and compact.
26
27       The following options are recognized.
28
29       -v     All lines but those matching are printed.
30
31       -c     Only a count of matching lines is printed.
32
33       -l     The names of files with matching lines are listed  (once)  sepa‐
34              rated by newlines.
35
36       -n     Each line is preceded by its line number in the file.
37
38       -b     Each line is preceded by the block number on which it was found.
39              This is sometimes useful in locating disk block numbers by  con‐
40              text.
41
42       -s     No output is produced, only status.
43
44       -h     Do not print filename headers with output lines.
45
46       -y     Lower  case  letters  in  the pattern will also match upper case
47              letters in the input (grep only).
48
49       -e expression
50              Same as a  simple  expression  argument,  but  useful  when  the
51              expression begins with a -.
52
53       -f file
54              The  regular  expression (egrep) or string list (fgrep) is taken
55              from the file.
56
57       -x     (Exact) only lines matched in their entirety are printed  (fgrep
58              only).
59
60       Care  should be taken when using the characters $ * [ ^ | ? ´ " ( ) and
61       \ in the expression as they are also meaningful to the  Shell.   It  is
62       safest to enclose the entire expression argument in single quotes ´ ´.
63
64       Fgrep  searches  for  lines that contain one of the (newline-separated)
65       strings.
66
67       Egrep accepts extended regular expressions.  In the following  descrip‐
68       tion `character' excludes newline:
69
70              A \ followed by a single character matches that character.
71
72              The character ^ ($) matches the beginning (end) of a line.
73
74              A .  matches any character.
75
76              A  single  character  not otherwise endowed with special meaning
77              matches that character.
78
79              A string enclosed in brackets [] matches  any  single  character
80              from  the string.  Ranges of ASCII character codes may be abbre‐
81              viated as in `a-z0-9'.  A ] may occur only as the first  charac‐
82              ter of the string.  A literal - must be placed where it can't be
83              mistaken as a range indicator.
84
85              A regular expression followed by * (+, ?) matches a sequence  of
86              0 or more (1 or more, 0 or 1) matches of the regular expression.
87
88              Two  regular expressions concatenated match a match of the first
89              followed by a match of the second.
90
91              Two regular expressions separated by | or newline match either a
92              match for the first or a match for the second.
93
94              A regular expression enclosed in parentheses matches a match for
95              the regular expression.
96
97       The order of precedence of operators at the same parenthesis  level  is
98       [] then *+? then concatenation then | and newline.
99

SEE ALSO

101       ed(1), sed(1), sh(1)
102

DIAGNOSTICS

104       Exit  status  is  0  if  any matches are found, 1 if none, 2 for syntax
105       errors or inaccessible files.
106

BUGS

108       Ideally there should be only one grep, but we don't know a single algo‐
109       rithm that spans a wide enough range of space-time tradeoffs.
110
111       Lines are limited to 256 characters; longer lines are truncated.
112
113
114
115                                                                       GREP(1)
Impressum