日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

cat-grep-sed应用案例

發(fā)布時間:2025/3/11 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 cat-grep-sed应用案例 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

案例:

已知文件test.txt內(nèi)容為:

test

liming

xiaoming

請打印出test.txt內(nèi)容時,不包含xiaoming字符串的命令。


創(chuàng)建文件test.txt

[root@hello110 testdata]# cat >>test.txt<<EOF
> test
> liming
> xiaoming
> EOF


實現(xiàn)

方法一:用head命令

[root@hello110 testdata]# head -2 test.txt?
test
liming


head命令:取頭部的前n行。如果不接參數(shù),默認是前10行。

命令:head -2 test.txt 或 head -n 2 test.txt


方法二:grep

grep命令:過濾器,把想要的或者不想要的分離開

想要什么:grep "要的內(nèi)容"

不想要什么:grep -v "不想要的內(nèi)容"

[root@hello110 testdata]# grep "liming" test.txt?
liming
[root@hello110 testdata]# grep -v "liming" test.txt?
test
xiaoming


grep畫蛇添足的用法:

[root@hello110 testdata]# cat test.txt |grep -v "liming" test.txt?
test
xiaoming

不專業(yè)!


方法三:sed

sed:過濾。格式:sed [-n] ?'/過濾的內(nèi)容/處理的命令' ?文件

-n:取消sed的默認輸出

-i:改變文件內(nèi)容

處理命令:有很多。p ?print。d ?delete,不刪除內(nèi)容。

[root@hello110 testdata]# sed '/liming/d' test.txt ?
test
xiaoming
[root@hello110 testdata]# cat test.txt ? ? ? ? ? ??
test
liming
xiaoming

[root@hello110 testdata]# sed -n '/liming/p' test.txt?
liming
[root@hello110 testdata]# sed '/liming/p' test.txt ? ?
test
liming
liming
xiaoming














總結(jié)

以上是生活随笔為你收集整理的cat-grep-sed应用案例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。