egrep

Find the specified string in the file

Supplementary instructions

egrep command is used to find a specified string in a file. The execution effect of egrep is similar to grep -E. The syntax and parameters used can refer to the grep command. The difference from grep lies in the method of interpreting strings. egrep is interpreted using extended regular expression syntax, while grep is interpreted using basic regular expression syntax. Extended regular expression is more standardized than basic regular expression.

grammar

egrep (option) (search pattern) (file name 1, file name 2, ...)

Example

Display characters that match the criteria in the file. For example, to find files containing the string "Linux" in all files in the current directory, you can use the following command:

egrep Linux*

The result looks like this:

# The following five lines contain Linux characters in testfile
testfile:hello Linux!
testfile:Linux is a free Unix-type operating system.
testfile:This is a Linux testfile!
testfile:Linux
testfile:Linux

# The following two lines contain Linux characters in testfile1
testfile1:helLinux!
testfile1:This a Linux testfile!

# The following two lines contain Linux characters in testfile_2
testfile_2:Linux is a free unix-type operating system
testfile_2:Linux test

Filter comment lines and blank lines

egrep -v '^\s*(#|$)' filename