bash 如何使用 grep 对多个文本字符串进行反向搜索
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20591383/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I Invert search using grep for multiple strings of text
提问by user2476714
I am trying filter out couple of blocks of text that keep repeating over and over in my log file. For eg;
我正在尝试过滤掉在我的日志文件中不断重复的几个文本块。例如;
grep -v ("string one that I don't want" \| "string two that I don't want") file.log
I tried several variations of this and tried tweaking the white spaces . Sometimes it will filter out the first string sometimes neither. What will be the correct format to filter out more than one block of text using grep ?
我尝试了几种变体并尝试调整空格。有时它会过滤掉第一个字符串,有时两者都不会。使用 grep 过滤掉多个文本块的正确格式是什么?
回答by anubhava
You can use -e
option multiple times in grep
to skip multiple search items:
您可以-e
多次使用选项grep
来跳过多个搜索项:
grep -v -e "string one that I don't want" -e "string two that I don't want" file.log
OR else use regex
using egrep
或其他使用regex
使用egrep
egrep -v 'string one|string two' file.log