Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ grep(1) — A/UX 3.0.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

awk(1)

csh(1)

ed(1)

ex(1)

ksh(1)

lex(1)

sed(1)

sh(1)

vi(1)




grep(1) grep(1)
NAME grep, egrep, fgrep - search a file for a specific pattern SYNOPSIS grep [-b] [-c] [-i] [-l] [-n] [-s] [-v] expression [file]... egrep [-b] [-c] [-e expression] [-f file] [-i] [-l] [-n] [-v] [expression] [file]... fgrep [-b] [-c] [-e expression] [-f file] [-i] [-l] [-n] [-v] [-x] [strings] [file]... ARGUMENTS -b Precedes each line by the block number on which it was found. This is sometimes useful in locating disk block numbers by context. -c Prints only a count of matching lines. -e expression Acts the same as a simple expression argument, but useful when the expression begins with a -. This option does not work with the grep command. expression Specifies the regular expression that is used in the egrep command. -f file Takes the regular expression (egrep) or strings list (fgrep) from the file. file Specifies the file that will be searched. -i Ignores upper/lowercase distinction during comparisons. -l Lists (once) only the names of files with matching lines, separated by newlines. -n Precedes each line by its relative line number in the file. -s Suppresses the error messages produced for nonexistent or unreadable files. This option is used for grep only. string Specifies the string of character to look for in the specified file. -v Prints all lines but those matching. January 1992 1



grep(1) grep(1)
-x Means exact. Only lines matched in their entirety are printed. This option is only used for fgrep. DESCRIPTION grep searches the input files (standard input default) for lines matching a pattern. Normally, each line found is copied to the standard output. The grep command patterns are limited regular expressions in the style of ed; they use a compact nondeterministic algorithm. egrep patterns are full regular expressions; they use a fast deterministic algorithm that sometimes needs exponential space. fgrep patterns are fixed strings; it is fast and compact. In all cases, the filename is output if there is more than one input file. Care should be taken when using the characters $, *, [, ^, |, (, ), and \ in expression, because they are also meaningful to the shell. It is safest to enclose the entire expression argument in single quotation marks ('...'). The fgrep command searches for lines that contain one of the strings separated by newlines. The egrep command accepts regular expressions as in ed(1), except for \( and \), with the addition of: 1. A regular expression followed by + matches one or more occurrences of the regular expression. 2. A regular expression followed by ? matches 0 or 1 occurrences of the regular expression. 3. Two regular expressions separated by | or by a newline match strings that are matched by either. 4. A regular expression may be enclosed in parentheses () for grouping. The order of precedence of operators is [], then *?+, then concatenation, then | and newline. EXAMPLES The command: grep -v -c 'regular' grep.1 reports a count of the number of lines that do not contain the word regular in the file grep.1. 2 January 1992



grep(1) grep(1)
LIMITATIONS Ideally there should be only one grep, but we do not know a single algorithm that spans a wide enough range of space- time tradeoffs. Lines are limited to BUFSIZ characters; longer lines are truncated. (BUFSIZ is defined in /usr/include/stdio.h.) The egrep command does not recognize ranges, such as [a-z], in character classes. If there is a line with embedded nulls, grep will only match up to the first null; if it matches, it will print the entire line. STATUS MESSAGES AND VALUES Exit status is 0 if any matches are found, 1 if none, 2 for syntax errors or inaccessible files (even if matches were found). FILES /bin/grep Executable file /bin/egrep Executable file /bin/fgrep Executable file SEE ALSO awk(1), csh(1), ed(1), ex(1), ksh(1), lex(1), sed(1), sh(1), vi(1) January 1992 3

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026