Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux egrep Command

Linux egrep Command

Linux Command Reference Linux Command Reference

The Linux egrep command is used to search for specified strings within files.

egrep works similarly to "grep -E"; its syntax and parameters can be referenced from the grep command. The difference from grep lies in how it interprets strings.

egrep interprets patterns using extended regular expression syntax, while grep uses basic regular expression syntax. Extended regular expressions are more standardized in expression than basic regular expressions.

Syntax



egrep [范本模式] [文件或目录] 

Parameter Description:

Example

Displays the characters in a file that match the condition. For example, to find all files in the current directory that contain the string "Linux", you can use the following command:



egrep Linux *

The result is as follows:



$ egrep Linux * #查找当前目录下包含字符串“Linux”的文件  

testfile:hello Linux! #以下五行为testfile 中包含Linux字符的行  

testfile:Linux is a free Unix-type operating system.  

testfile:This is a Linux testfile!  

testfile:Linux  

testfile:Linux  

testfile1:helLinux! #以下两行为testfile1中含Linux字符的行  

testfile1:This a Linux testfile!  

#The following two lines contain Linux characters in testfile_2

testfile_2:Linux is a free unix-type opterating system.  

testfile_2:Linux test  

xx00:hello Linux! #xx00包含Linux字符的行  

xx01:Linux is a free Unix-type operating system. #以下三行为xx01包含Linux字符的行  

xx01:This is a Linux testfile!  

xx01:Linux 

Linux Command Reference Linux Command Reference