“egrep” stands for “Extended Global Regular Expression Print”. It is a pattern searching command which is similar to grep command in linux. egrep renders the lines that match the pattern as an expanded regular expression. It reads a file line by line, looking for the search string or regular expression and printing out those lines that contain it.
Command
$ egrep [options] pattern [file] |
Options
Here are details about some options.
Option | Details |
---|---|
-i | Ignore case differences in patterns and input data so that characters that only differ in case will match. |
-f | Obtain patterns from File, one per line. |
-e Pattern | Tells you about a pattern. It works like a simple pattern, but it is useful when the pattern starts with a minus sign (-). |
-h | Display the matched lines, but do not display the filenames. |
-c | Print out the number of matching lines in each file. |
-l | Only shows a list of filenames. |
-n | Show the lines that match and their line numbers. |
-v | This makes all the lines that do not fit the pattern print out. |
-w | Select only those lines containing matches that form whole words. |
-x | Displays lines that exactly match the pattern without any extra characters. |
-R | Read all files under each directory, recursively. |
Examples
- Now, let us see some examples.
egrep -i linux linux_introduction.txt
egrep -c Linux linux_introduction.txt
egrep -w Linux linux_introduction.txt
egrep -n Linux linux_introduction.txt
egrep -l Linux *
egrep -x Ubuntu linux_distributions.txt