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.   Grep  patterns are limited regular
19       expressions in the style of ex(1); it uses a  compact  nondeterministic
20       algorithm.  Egrep patterns are full regular expressions; it uses a fast
21       deterministic algorithm that sometimes needs exponential space.   Fgrep
22       patterns  are  fixed  strings;  it  is fast and compact.  The following
23       options are recognized.
24
25       -v     All lines but those matching are printed.
26
27       -x     (Exact) only lines matched in their entirety are printed  (fgrep
28              only).
29
30       -c     Only a count of matching lines is printed.
31
32       -l     The  names  of files with matching lines are listed (once) sepa‐
33              rated by newlines.
34
35       -n     Each line is preceded by its relative line number in the file.
36
37       -b     Each line is preceded by the block number on which it was found.
38              This  is sometimes useful in locating disk block numbers by con‐
39              text.
40
41       -i     The case of letters is ignored in making comparisons — that  is,
42              upper  and lower case are considered identical.  This applies to
43              grep and fgrep only.
44
45       -s     Silent mode.  Nothing is printed (except error messages).   This
46              is useful for checking the error status.
47
48       -w     The  expression  is  searched for as a word (as if surrounded by
49              `\<' and `\>', see ex(1).)  (grep only)
50
51       -e expression
52              Same as a  simple  expression  argument,  but  useful  when  the
53              expression begins with a -.
54
55       -f file
56              The  regular  expression (egrep) or string list (fgrep) is taken
57              from the file.
58
59       In all cases the file name is shown if there is  more  than  one  input
60       file.  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 other than newline matches
71              that character.
72
73              The character ^ matches the beginning of a line.
74
75              The character $ matches the end of a line.
76
77              A .  (period) matches any character.
78
79              A single character not otherwise endowed  with  special  meaning
80              matches that character.
81
82              A  string  enclosed  in brackets [] matches any single character
83              from the string.  Ranges of ASCII character codes may be  abbre‐
84              viated  as in `a-z0-9'.  A ] may occur only as the first charac‐
85              ter of the string.  A literal - must be placed where it can't be
86              mistaken as a range indicator.
87
88              A  regular  expression  followed  by  an  * (asterisk) matches a
89              sequence of 0 or more matches of the regular expression.  A reg‐
90              ular  expression  followed by a + (plus) matches a sequence of 1
91              or more matches of the regular expression.  A regular expression
92              followed  by  a  ?  (question mark) matches a sequence of 0 or 1
93              matches of the regular expression.
94
95              Two regular expressions concatenated match a match of the  first
96              followed by a match of the second.
97
98              Two regular expressions separated by | or newline match either a
99              match for the first or a match for the second.
100
101              A regular expression enclosed in parentheses matches a match for
102              the regular expression.
103
104       The  order  of precedence of operators at the same parenthesis level is
105       [] then *+? then concatenation then | and newline.
106
107       Ideally there should be only one grep, but we don't know a single algo‐
108       rithm that spans a wide enough range of space-time tradeoffs.
109

SEE ALSO

111       ex(1), sed(1), sh(1)
112

DIAGNOSTICS

114       Exit  status  is  0  if  any matches are found, 1 if none, 2 for syntax
115       errors or inaccessible files.
116

BUGS

118       Lines are limited to 256 characters; longer lines are truncated.
119
120
121
1224th Berkeley Distribution       April 29, 1985                         GREP(1)
Impressum