熱搜:win11繞過硬件限制安裝 一鍵重裝Win10系統(tǒng) 最干凈的u盤啟動(dòng)盤 真正純凈版的win7系統(tǒng)
時(shí)間:2014-12-30 16:00:08 作者:qipeng 來(lái)源:系統(tǒng)之家 1. 掃描二維碼隨時(shí)看資訊 2. 請(qǐng)使用手機(jī)瀏覽器訪問: https://m.xitongzhijia.net/xtjc/20141230/33749.html 手機(jī)查看 評(píng)論 反饋
實(shí)例8:找出已u開頭的行內(nèi)容
命令:cat test.txt |grep ^u
輸出:
代碼如下:
。踨oot@localhost test]# cat test.txt |grep ^u
ubuntu
ubuntu linux
[root@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
[root@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
。踨oot@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
輸出:
代碼如下:
[root@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è)了解。
發(fā)表評(píng)論
共0條
評(píng)論就這些咯,讓大家也知道你的獨(dú)特見解
立即評(píng)論以上留言僅代表用戶個(gè)人觀點(diǎn),不代表系統(tǒng)之家立場(chǎng)