egrep command in Linux

“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.

OptionDetails
-iIgnore case differences in patterns and input data so that characters that only differ in case will match.
-fObtain patterns from File, one per line.
-e PatternTells you about a pattern. It works like a simple pattern, but it is useful when the pattern starts with a minus sign (-).
-hDisplay the matched lines, but do not display the filenames.
-cPrint out the number of matching lines in each file.
-lOnly shows a list of filenames.
-nShow the lines that match and their line numbers.
-vThis makes all the lines that do not fit the pattern print out.
-wSelect  only  those  lines  containing  matches  that form whole words.
-xDisplays lines that exactly match the pattern without any extra characters.
-RRead  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

Feedback

Do you want to provide us with feedback? Provide us with feedback directly at info@elearnbee.com.

Share us:

AD BLOCK 1