系統(tǒng)之家 - 系統(tǒng)光盤下載網(wǎng)站!

當(dāng)前位置:系統(tǒng)之家 > 系統(tǒng)教程 > Linux使用grep命令搜索文件

Linux如何使用grep命令搜索文本文件(4)

時(shí)間:2014-12-30 16:00:08 作者:qipeng 來源:系統(tǒng)之家 1. 掃描二維碼隨時(shí)看資訊 2. 請使用手機(jī)瀏覽器訪問: https://m.xitongzhijia.net/xtjc/20141230/33749.html 手機(jī)查看 評論

  實(shí)例8:找出已u開頭的行內(nèi)容

  命令:cat test.txt |grep ^u

  輸出:

  代碼如下:

  [root@localhost test]# cat test.txt |grep ^u

  ubuntu

  ubuntu linux

 。踨oot@localhost test]#

  實(shí)例9:輸出非u開頭的行內(nèi)容

  命令:cat test.txt |grep ^[^u]

  輸出:

  代碼如下:

 。踨oot@localhost test]# cat test.txt |grep ^[^u]

  hnlinux

  peida.cnblogs.com

  redhat

  Redhat

  linuxmint

 。踨oot@localhost test]#

  實(shí)例10:輸出以hat結(jié)尾的行內(nèi)容

  命令:cat test.txt |grep hat$

  輸出:

  代碼如下:

 。踨oot@localhost test]# cat test.txt |grep hat$

  redhat

  Redhat

  [root@localhost test]#

  實(shí)例11:

  命令: ifconfig eth0|grep “[0-9]\{1,3\}\。[0-9]\{1,3\}\。[0-9]\{1,3\}\。[0-9]\{1,3\}”

  輸出:

  代碼如下:

 。踨oot@localhost test]# ifconfig eth0|grep “[0-9]\{1,3\}\。[0-9]\{1,3\}\。[0-9]\{1,3\}\。[0-9]\{1,3\}”

  inet addr:192.168.120.204 Bcast:192.168.120.255 Mask:255.255.255.0

 。踨oot@localhost test]# ifconfig eth0|grep -E “([0-9]{1,3}\。){3}[0-9]”

  inet addr:192.168.120.204 Bcast:192.168.120.255 Mask:255.255.255.0

  [root@localhost test]#

  實(shí)例12:顯示包含ed或者at字符的內(nèi)容行

  命令:cat test.txt |grep -E “ed|at”

  輸出:

  代碼如下:

 。踨oot@localhost test]# cat test.txt |grep -E “peida|com”

  peida.cnblogs.com

  [root@localhost test]# cat test.txt |grep -E “ed|at”

  redhat

  Redhat

 。踨oot@localhost test]#

  實(shí)例13:顯示當(dāng)前目錄下面以.txt 結(jié)尾的文件中的所有包含每個(gè)字符串至少有7個(gè)連續(xù)小寫字符的字符串的行

  命令:grep ‘[a-z]\{7\}’ *.txt

  輸出:

  代碼如下:

 。踨oot@localhost test]# grep ‘[a-z]\{7\}’ *.txt

  test.txt:hnlinux

  test.txt:peida.cnblogs.com

  test.txt:linuxmint

 。踨oot@localhost test]#

  上面就是Linux使用grep命令搜索文本文件的方法介紹了,除了文本的搜索,還能從文件中查找關(guān)鍵詞,查找指定進(jìn)程,本文已通過各種實(shí)例進(jìn)行介紹,希望你有個(gè)了解。

標(biāo)簽 命令 grep

發(fā)表評論

0

沒有更多評論了

評論就這些咯,讓大家也知道你的獨(dú)特見解

立即評論

以上留言僅代表用戶個(gè)人觀點(diǎn),不代表系統(tǒng)之家立場

其他版本軟件

熱門教程

人氣教程排行

Linux系統(tǒng)推薦

官方交流群 軟件收錄