[精讚] [會員登入]

[Linux] grep 排除特定字串

使用 -v 參數可以讓grep排除特定字串的方法

分享完整連結 //n.sfs.tw/m10916

分享連結 [Linux] grep 排除特定字串@精讚
(文章歡迎轉載,請尊重版權註明連結來源)
2023-11-02 13:51:55 By 張○○

使用 grep -v 參數可以排除特定字串,範例:

# Let's assume we have a file called data.txt with the following content:
# John
# Mary
# Paul
# John Paul
# If you want to search for 'John' but don't want lines with 'Paul' to appear, you can use grep exclusion like this:
grep 'John' data.txt | grep -v 'Paul'
# This will return only 'John' and excludes 'John Paul'

排除 'exclude_this' 字串的行
grep -v 'exclude_this' example.txt

排除以 'word' 開頭的行
grep -v '^word' filename

Listen5144埠並排除字串 'detected' 的行
nc -u -l 5144 | grep -v 'detected'

 

相關連結

https://ioflood.com/blog/grep-exclude-how-to-use-v-to-exclude-words-patterns-or-files-in-grep/

END
你可能有興趣

[Rocky9] 安裝node.js 18, node.js 20

原本的nodejs16在使用 quasar dev時出現錯誤,得升級成18版以上

[SSL] Could not read certificate from server.cer 的錯誤排除

在轉換ssl憑證時,出現無法讀取的錯誤,可是怎麼看憑證都很正常,該怎麼解決?

[Linux] 如何能知道我是什麼時候安裝系統的?

linux想知道什麼時候裝系統的? 不必憑記憶。

地圖填色的網站

我們想為國家填色不需要小畫家,這個網站能幫助你

[Linux] 列出所有目錄及所占空間的方法

想知道目錄下的所有目錄所占的空間大小?

[Linux] grep 排除特定字串

使用 -v 參數可以讓grep排除特定字串的方法