[精讚] [會員登入]

[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
你可能有興趣

[地理] 澳洲柏斯的位置竟然比台灣還要西邊

這近我驚奇的發現,澳洲柏斯的精度竟然比臺灣甚至今晚還要來的西邊

WarSpotting 統計俄國在烏克蘭戰爭中到底是損失了多少軍事裝備或人員

這個網站可以看到俄羅斯在戰場上的軍事人員裝備損失,非常詳細

Mac上 vim的複製貼上不能用

在freebsd系統中發現vim裡的command+c沒辦法選取複製,但command+v可以貼上

check-host 從世界各地檢查你的網站能不能連線?

檢測你的網站能不能暢通?這個網站可讓你知道你的網站是不是「網際網路」還是「區域網路」?

[Smarty4] 出現 modifiers 函式不能用的問題

當我把smarty由3版更新到4.5.1版的時候,出現了Using unregistered function xx in a template這樣的錯誤,該如何解決?

[Docker] docker中要怎麼修改影像的名稱,rename image

透過 build來的image如果沒有指定名稱,事後要怎麼修改影像的名稱?