grep(1) CLIX grep(1)
NAME
grep - Searches a file for a pattern
SYNOPSIS
grep [flag ... ] limited_regexpr [file ... ]
FLAGS
The following flags are available:
-b Precedes each line by the block number on which it was found. This
can be useful in locating block numbers by context (first block is
0).
-c Displays only a count of the lines that contain the pattern.
-i Ignores upper/lowercase distinction during comparisons.
-l Displays the names of files with matching lines once, separated by
newlines. Does not repeat the names of files when the pattern is
found more than once.
-n Precedes each line by its line number in the file (first line is 1).
-s Suppresses error messages about nonexistent or unreadable files
-v Displays all lines except those that contain the pattern.
DESCRIPTION
The grep command searches files for a pattern and displays all lines that
contain the pattern. This command uses limited regular expressions, in
other words, expressions that have string values that use a subset of the
possible alphanumeric and special characters. The regular expressions are
like those used with ed to match the patterns. The grep command uses a
compact nondeterministic algorithm.
If no files are specified, grep assumes stdin. Normally, each line found
is copied to stdout. The filename is displayed before each line found if
there is more than one input file.
EXAMPLES
1. To search for and display all lines containing the string ``hello'',
along with the line numbers, enter the following:
grep -n hello bigfile
2/94 - Intergraph Corporation 1
grep(1) CLIX grep(1)
2. The following command counts all lines in bigfile that do not contain
the string ``hello'':
grep -civ hello bigfile
The search is case-insensitive.
3. This example provides the names of all files in the current directory
that contain the string ``hello'':
grep -l hello *
NOTES
Lines are limited to BUFSIZ characters; longer lines are truncated.
BUFSIZ is defined in /usr/include/stdio.h.
If there is a line with embedded nulls, grep will only match up to the
first null; if it matches, it will display the entire line.
CAUTIONS
Be careful using the characters $, *, [, ^, |, (, ), and \ in the
limited_regexpr because they are also meaningful to the shell. It is
safest to enclose the entire limited_regexpr in single quotes '...'.
DIAGNOSTICS
Syntax error
A search pattern was given that was not valid.
Cannot open file
One of the files being searched did not have read permission or did
not exist.
EXIT VALUES
0 If any matches are found
1 If no matches are found
2 For syntax errors or inaccessible files (even if matches were found)
RELATED INFORMATION
Commands: ed(1), egrep(1), fgrep(1), sed(1), sh(1)
2 Intergraph Corporation - 2/94