grep(1) MPE/iX Shell and Utilities grep(1)
______________________________________________________________________
NAME
grep, egrep, fgrep -- match patterns in a file
SYNOPSIS
egrep [-bcilnqsvx] [-e pattern] ... [-f patternfile] ... [pat-
tern] [file...]
fgrep [-bcilnqsvx] [-e pattern] ... [-f patternfile] ... [pat-
tern] [file...]
grep [-bcEFilnqsvx] [-e pattern] ... [-f patternfile] ... [pat-
tern] [file...]
DESCRIPTION
fgrep searches files for one or more pattern arguments. It does
not use regular expressions; instead, it does direct string com-
parison to find matching lines of text in the input.
egrep works in a similar way, but uses extended regular expres-
sion matching, as described in regexp(3). If you include special
characters in patterns typed on the command line, escape them by
enclosing them in apostrophes to prevent inadvertent misinterpre-
tation by the shell or command interpreter. To match a character
that is special to egrep, put a backslash (\) in front of the
character. It is usually simpler to use fgrep when you don't
need special pattern matching.
grep is a combination of fgrep and egrep. If you do not specify
either -E or -F, grep behaves like egrep, but matches basic regu-
lar expressions instead of extended ones. You can specify a pat-
tern to search for with either the -e or -f option. If you spec-
ify neither option, grep (or egrep or fgrep) takes the first non-
option argument as the pattern for which to search. If grep
finds a line that matches a pattern, it displays the entire line.
If you specify multiple input files, the name of the current file
precedes each output line.
Options
grep accepts all of the following options while egrep and fgrep
accept all but the -E and -F options.
-b precedes each matched line with its file block number.
-c displays only a count of the number of matched lines and not
the lines themselves.
-E causes grep to behave like egrep.
-e pattern
specifies one or more patterns separated by newlines for
which grep is to search.
-F causes grep to behave like fgrep.
1
grep(1) MPE/iX Shell and Utilities grep(1)
______________________________________________________________________
-f patternfile
reads one or more patterns from patternfile. Patterns in
patternfile are separated by newlines.
-i ignores the case of the strings being matched.
-l lists only the file names that contain the matching lines.
-n precedes each matched line with its file line number.
-q suppresses output and simply returns appropriate return
code.
-s suppresses the display of any error messages for nonexistent
or unreadable files.
-v complements the sense of the match; that is, displays all
lines not matching a pattern.
-x requires a string to match an entire line.
EXAMPLES
To display every line mentioning an astrological element:
egrep "earth|air|fire|water" astro.log
DIAGNOSTICS
Possible exit status values are:
0 The command found at least one match for pattern.
1 The command found no matches for pattern.
2 An error occurred.
If the program fails to open one input file, it tries to go
on to look at any remaining input files, but it returns 2
even if it succeeds in finding matches in other input files.
Messages
Message: input file "filename": system error
Cause: See syserror(3).
Action: See syserror(3).
Message: Missing -e pattern
Cause: You specified the -e option but did not provide a pat-
tern with it.
Action: Provide a pattern following the -e option.
Message: Missing -f file
Cause: You specified the -f option but did not provide a file
with it.
2
grep(1) MPE/iX Shell and Utilities grep(1)
______________________________________________________________________
Action: Provide a file following the -f.
Message: no room for buffers
Cause: There were not enough free system resources for grep to
allocate the buffers that it requires.
Action: Free up more system resources.
Message: out of space for pattern "string"
Cause: grep did not have enough system resources available to
store the code needed to work with the given pattern
(regular expression). The usual cause is that the pat-
tern is very complex.
Action: Make the pattern simpler, or free up more system
resources.
Message: read error on file "filename": system error
Cause: See syserror(3).
Action: See syserror(3).
Message: regular expression error: regular expression error
Cause: See regerror(3).
Action: See regerror(3).
Message: string file "filename": system error
Cause: See syserror(3).
Action: See syserror(3).
Message: Unknown option "-option"
Cause: You specified an option that is not valid for grep.
Action: Check the DESCRIPTION section for a list of valid grep
options.
PORTABILITY
POSIX.2. x/OPEN Portability Guide 4.0. All UNIX systems.
Only the actual grep command is a part of the POSIX standard.
The egrep and fgrep commands are extensions. The -b option is
also an extension to the POSIX standard.
LIMITS
The longest input record (line) is restricted by the system vari-
able LINE_MAX. It is always at least 2048 bytes. Longer lines
are treated as two or more records.
MPE/iX NOTES
For information on how the current MPE/iX implementation may
affect the operation of this utility, see Appendix A, MPE/iX
Implementation Considerations.
SEE ALSO
ed(1), find(1), gres(1), regexp(3)
3