Linux egrep命令

Linux 命令大全 Linux 命令大全

Linux egrep命令用於在檔內查找指定的字串。

egrep執行效果與"grep-E"相似,使用的語法及參數可參照grep指令,與grep的不同點在於解讀字串的方法。

egrep是用extended regular expression語法來解讀的,而grep則用basic regular expression 語法解讀,extended regular expression比basic regular expression的表達更規範。

語法

egrep [範本模式] [檔或目錄]

參數說明:

  • [範本模式] :查找的字串規則。
  • [檔或目錄] :查找的目標檔或目錄。

實例

顯示檔中符合條件的字元。例如,查找當前目錄下所有檔中包含字串"Linux"的檔,可以使用如下命令:

egrep Linux *

結果如下所示:

$ 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!
#以下兩行為testfile_2 中包含Linux字元的行
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 命令大全 Linux 命令大全