在文件內查找指定的字符串
egrep命令 用于在文件內查找指定的字符串。egrep執行效果與grep -E
相似,使用的語法及參數可參照grep指令,與grep的不同點在于解讀字符串的方法。egrep是用extended regular expression語法來解讀的,而grep則用basic regular expression 語法解讀,extended regular expression比basic regular expression的表達更規范。
egrep(選項)(查找模式)(文件名1,文件名2,……)
顯示文件中符合條件的字符。例如,查找當前目錄下所有文件中包含字符串"Linux"的文件,可以使用如下命令:
egrep Linux *
結果如下所示:
# 以下五行為 testfile 中包含Linux字符的行
testfile:hello Linux!
testfile:Linux is a free Unix-type operating system.
testfile:This is a Linux testfile!
testfile:Linux
testfile:Linux
# 以下兩行為testfile1中含Linux字符的行
testfile1:helLinux!
testfile1:This a Linux testfile!
# 以下兩行為 testfile_2 中包含Linux字符的行
testfile_2:Linux is a free unix-type opterating system
testfile_2:Linux test