14
我正在過濾掉幾個在我的日誌文件中不斷重複的文本塊。例如;如何反轉使用grep查找多個文本字符串
grep -v ("string one that I don't want" \| "string two that I don't want") file.log
我嘗試了幾種變化,嘗試調整空格。有時它會過濾出第一個字符串,有時候也不會。什麼是使用grep過濾掉多個文本塊的正確格式?
我正在過濾掉幾個在我的日誌文件中不斷重複的文本塊。例如;如何反轉使用grep查找多個文本字符串
grep -v ("string one that I don't want" \| "string two that I don't want") file.log
我嘗試了幾種變化,嘗試調整空格。有時它會過濾出第一個字符串,有時候也不會。什麼是使用grep過濾掉多個文本塊的正確格式?
您可以使用-e
選項多次在grep
跳過多個搜索項目:
grep -v -e "string one that I don't want" -e "string two that I don't want" file.log
或者使用egrep
egrep -v 'string one|string two' file.log
感謝您使用
regex
。兩種方法都有效。我曾嘗試使用egrep方法。但我想我會在管道角色之間放置空間。所以當時它不起作用。現在它可以工作。 – user2476714