我正在尝试过滤掉在我的日志文件中反复重复的几个文本块.例如;
grep -v ("string one that I don't want" \| "string two that I don't want") file.log
Run Code Online (Sandbox Code Playgroud)
我尝试了几种变体并尝试调整白色空间.有时它有时也不会过滤掉第一个字符串.使用grep过滤掉多个文本块的正确格式是什么?
anu*_*ava 41
您可以-e多次使用选项grep来跳过多个搜索项:
grep -v -e "string one that I don't want" -e "string two that I don't want" file.log
Run Code Online (Sandbox Code Playgroud)
或者regex使用egrep
egrep -v 'string one|string two' file.log
Run Code Online (Sandbox Code Playgroud)