Searches a file for a pattern.
egrep [ -h ] [ -i ] [ -p[ Separator ] ] [ -s ] [ -v ] [ -w ] [ -x ] [ -y ] [ [ -b ] [ -n ] | [ -c | -l | -q ] ] { { -ePattern | -fStringFile } ... | Pattern } [ File ... ]
The egrep command searches an input file (standard input by default) for lines matching a pattern specified by the Pattern parameter. These patterns are full regular expressions as in the ed command (except for the \ (backslash) and \\ (double backslash)). The following rules also apply to the egrep command:
The new-line character will not be matched by the regular expressions.
The order of precedence for operators is [, ], *, ?, +, concatenation, | and the new-line character.
Note: The egrep command is the same as the grep command with the -E flag, except that error and usage messages are different and the -s flag functions differently.
The egrep command displays the file containing the matched line if you specify more than one File parameter. Characters with special meaning to the shell ($, *, [, |, ^, (, ), \ ) must be in quotation marks when they appear in the Pattern parameter. When the Pattern parameter is not a simple string, you usually must enclose the entire pattern in single quotation marks. In an expression such as [a-z], the minus means through according to the current collating sequence. A collating sequence may define equivalence classes for use in character ranges. It uses a fast, deterministic algorithm that sometimes needs exponential space.
Notes:
- Lines are limited to 2048 bytes.
- Paragraphs (under the -p flag) are currently limited to a length of 5000 characters.
- Do not run the grep command on a special file because it produces unpredictable results.
- Input lines should not contain the NULL character.
- Input files should end with the newline character.
- Although some flags can be specified simultaneously, some flags override others. For example, if you specify -l and -n together, only file names are written to standard output.
This command returns the following
exit values:
0 | A match was found. |
1 | No match was found. |
>1 | A syntax error was found or a file was inaccessible (even if matches were found). |
To use an extended pattern that contains some of the pattern-matching characters +, ?, |, (, and ), enter:
egrep "\( *([[:lower:][:upper:]]*|[:digit:]*\)" my.txt
This displays lines that contain letters in parentheses or digits in parentheses, but not parenthesized letter-digit combinations. It matches (y) and (783902), but not (alpha19c).
Note: When using the egrep command, \ ( (backslash followed by open parenthesis) or \ ( (backslash followed by close parenthesis) match parentheses in the text, but ( (open parenthesis) and ) (closed parenthesis) are special characters that group parts of the pattern. The reverse is true when using the grep command.
/usr/bin/egrep | Contains the hard link to the egrep command. |
/bin/egrep | Specifies the symbolic link to the egrep command. |
The awk command, ed command, fgrep command, grep command, sed command.
Files Overview in AIX 5L Version 5.1 System User's Guide: Operating System and Devices.
Input and Output Redirection Overview in AIX 5L Version 5.1 System User's Guide: Operating System and Devices.
Shells Overview in AIX 5L Version 5.1 System User's Guide: Operating System and Devices.
National Language Support Overview for Programmers in AIX 5L Version 5.1 General Programming Concepts: Writing and Debugging Programs.