xref: /csrg-svn/usr.bin/grep/egrep/grep.1 (revision 47344)
143694Scael.\" Copyright (c) 1980, 1990 The Regents of the University of California.
243694Scael.\" All rights reserved.
319148Smckusick.\"
443694Scael.\" %sccs.include.redist.man%
519148Smckusick.\"
6*47344Scael.\"     @(#)grep.1	6.6 (Berkeley) 03/14/91
743694Scael.\"
8*47344Scael.Vx
9*47344Scael.Vx
1043694Scael.Dd
1143694Scael.Dt GREP 1
12*47344Scael.Os
1343694Scael.Sh NAME
1443694Scael.Nm grep
1543694Scael.Nd file pattern searcher
1643694Scael.Sh SYNOPSIS
1743694Scael.Nm grep
1843694Scael.Op Fl bchilnosvw
1943694Scael.Op Fl e Ar pattern
2043694Scael.Ar
2143694Scael.Nm egrep
2243694Scael.Op Fl bchilnosv
2343694Scael.Op Fl e Ar pattern
2443694Scael.Op Fl f Ar pattern_file
2543694Scael.Ar
2643694Scael.Nm fgrep
2743694Scael.Op Fl bchilnosvx
2843694Scael.Op Fl e Ar pattern
2943694Scael.Op Fl f Ar pattern_file
3043694Scael.Ar
3143694Scael.Sh DESCRIPTION
3243694ScaelThe
3343694Scael.Nm grep
3443694Scaelutilities search the given input files selecting lines
3543694Scaelwhich match one or more patterns; the type of patterns is controlled
3643694Scaelby the options specified.
3743694ScaelBy default, a pattern
3843694Scaelmatches an input line if any regular expression (RE) in the
3943694Scaelpattern matches the input line without its trailing <new-line>.
4043694ScaelA null RE matches every line.
4143694ScaelEach input line that matches at
4243694Scaelleast one of the patterns is written to the standard output.
4343694Scael.Pp
4443694ScaelFor simple patterns or
4543694Scael.Xr ex 1
4643694Scaelor
4743694Scael.Xr ed 1
4843694Scaelstyle regular expressions, the
4943694Scael.Nm grep
5043694Scaelutility is used.
5143694ScaelThe
5243694Scael.Nm egrep
5343694Scaelutility
5443694Scaelcan handle extended regular expressions and
5543694Scaelembedded <newline>s in pattern
5643694Scael.Nm Fgrep
5743694Scaelis quick but is designed to handle fixed strings.
5843694ScaelA fixed string
5943694Scaelis a string of characters,
6043694Scaeleach character
6143694Scaelis matched only by itself.
6243694ScaelThe pattern
6343694Scaelvalue can consist of multiple lines with
6443694Scaelembedded <newline>s.
6543694ScaelIn this case, the <newline>s
6643694Scaelact as alternation characters, allowing any of the
6743694Scaelpattern lines to match a portion of the input.
6843694Scael.Pp
6943694ScaelThe following options are available:
7043694Scael.Pp
7143694Scael.Tw Fl
7243694Scael.Tp Fl b
7343694ScaelThe block number on the disk in which a matched pattern is located
7443694Scaelis displayed in front of the respective matched line.
7543694Scael.Tp Fl c
7643694ScaelOnly a count of selected lines is written to standard
7743694Scaeloutput.
7843694Scael.Tc Fl e
7943694Scael.Ws
8043694Scael.Ar expression
8143694Scael.Cx
8243694ScaelSpecify a pattern used during the search of the
8343694Scaelinput.
8443694ScaelMultiple
8543694Scael.Fl e
8643694Scaeloptions can be used to specify
8743694Scaelmultiple patterns; an input line is selected of it
8843694Scaelmatches any of the specified patterns.
8943694Scael.Tc Fl f
9043694Scael.Ws
9143694Scael.Ar pattern_file
9243694Scael.Cx
9343694ScaelThe pattern is read from the file named by the
9443694Scaelpathname pattern_file.
9543694ScaelTrailing newlines
9643694Scaelin the pattern_file are ignored.
9743694Scael.Pf \&( Nm egrep
9843694Scaeland
9943694Scael.Nm fgrep
10019148Smckusickonly).
10143694Scael.Tp Fl h
10232367SbosticNever print filename headers with output lines.
10343694Scael.Tp Fl i
10443694ScaelThe case of letters is ignored in making comparisons \- that is, upper and
10543694Scaellower case are considered identical.
10643694Scael.Tp Fl l
10743694ScaelOnly the names of files containing selected lines
10843694Scaelare written to standard output.
10943694ScaelPathnames are
11043694Scaellisted once per file searched.
11143694ScaelIf the standard
11243694Scaelinput is searched, the pathname
11344955Scael.Sq Fl
11443694Scaelis written.
11543694Scael.Tp Fl n
11643694ScaelEach output line is preceded by its relative line
11743694Scaelnumber in the file; each file starting at line 1.
11843694ScaelThe line number counter is reset for each file processed.
11943694ScaelThis option is ignored if
12043694Scael.Fl c ,
12143694Scael.Fl l ,
12243694Scaelor
12343694Scael.Fl s
12443694Scaelis
12543694Scaelspecified.
12643694Scael.Tp Fl o
12732367SbosticAlways print filename headers with output lines.
12843694Scael.Tp Fl s
12919149SmckusickSilent mode.  Nothing is printed (except error messages).
13019148SmckusickThis is useful for checking the error status.
13143694Scael.Tp Fl v
13243694ScaelSelected lines are those
13343694Scael.Em not
13443694Scaelmatching the specified
13543694Scaelpatterns.
13643694Scael.Tp Fl x
13743694ScaelOnly input lines selected against an entire fixed
13843694Scaelstring or regular expression are considered to be
13943694Scaelmatching lines.
14043694Scael.Pf \&( Nm fgrep
14143694Scaelonly).
14243694Scael.Tp Fl w
14319148SmckusickThe expression is searched for as a word
14419148Smckusick(as if surrounded by `\e<' and `\e>', see
14543694Scael.Xr ex  1  . )
14643694Scael.Pf \&( Nm grep
14743694Scaelonly)
14843694Scael.Pp
14943694Scael.Tp
15043694ScaelIf no file arguments are specified, the
15143694Scaelstandard input is used.
15243694Scael.Pp
15343694ScaelThe
15443694Scael.Nm grep
15543694Scaelutility exits with one of the following values:
15644955Scael.Dw Ds
15744955Scael.Dp Li \&0
15843694ScaelOne or more lines were selected.
15944955Scael.Dp Li \&1
16043694ScaelNo lines were selected.
16144955Scael.Dp Li \&>1
16243694ScaelAn error occurred.
16344955Scael.Dp
16443694Scael.Sh EXTENDED REGULAR EXPRESSIONS
16543694ScaelThe following characters are interpreted by
16643694Scael.Nm egrep :
16743694Scael.Tw Ds
16843694Scael.Tp Cm \&$
16943694ScaelAlign the match from the end of the line.
17043694Scael.Tp Cm \&^
17143694ScaelAlign the match from the beginning of the line.
17243694Scael.Tp Cm \&|
17343694ScaelAdd another pattern (see example below).
17443694Scael.Tp Cm \&?
17543694ScaelMatch 1 or less sequential repetitions of the pattern.
17643694Scael.Tp Cm \&+
17743694ScaelMatch 1 or more sequential repetitions of the pattern.
17843694Scael.Tp Cm \&*
17943694ScaelMatch 0 or more sequential repetitions of the pattern.
18043694Scael.Tp Cm \&[]
18143694ScaelMatch any single character or range of characters
18243694Scaelenclosed in the brackets.
18343694Scael.Tp Cm \&\e
18443694ScaelEscape special characters which have meaning to
18543694Scael.Nm egrep ,
18643694Scaelthe set of {$,.,^,[,],|,?,+,*,(,)}.
18743694Scael.Tp
18843694Scael.Sh EXAMPLES
18943694ScaelTo find all occurances of the word patricia in a file:
19044955Scael.Pp
19143694Scael.Dl grep patricia myfile
19243694Scael.Pp
19343694ScaelTo find all occurences to the pattern
19443694Scael.Sq Li \&.Pp
19543694Scaelat the beginning of a line:
19644955Scael.Pp
19743694Scael.Dl grep '^\e.Pp'
19843694Scael.Pp
19943694ScaelThe apostrophys assure the entire expression is evaluated by
20043694Scael.Nm grep
20143694Scaelinstead of by the
20243694Scaelusers shell.
20343694ScaelThe carat or hat
20443694Scael.Sq Li \&^
20543694Scaelmeans
20643694Scael.Em from the beginning of a line ,
20743694Scaeland the
20843694Scael.Sq Li \&\e
20943694Scaelescapes the
21043694Scael.Sq Li \&.
21143694Scaelwhich would otherwise match any character.
21243694Scael.Pp
21343694ScaelA simple example of an extended regular expression:
21444955Scael.Pp
21543694Scael.Dl egrep '19|20|25' calendar
21643694Scael.Pp
21743694ScaelPeruses the file calendar looking for either 19, 20
21843694Scaelor 25.
21943694Scael.Sh SEE ALSO
22043694Scael.Xr ed 1 ,
22143694Scael.Xr ex 1 ,
22243694Scael.Xr sed 1
22343694Scael.Sh HISTORY
22443694Scael.Nm Grep
22543694Scaelappeared in Version 6 AT&T Unix.
22643694Scael.Sh BUGS
22719149SmckusickLines are limited to 256 characters; longer lines are truncated.
228