我试图使用尾部查看日志文件,-f并希望排除包含以下字符串的所有行:
"Nopaging the limit is"` and `"keyword to remove is"
Run Code Online (Sandbox Code Playgroud)
我可以排除一个这样的字符串:
tail -f admin.log|grep -v "Nopaging the limit is"
Run Code Online (Sandbox Code Playgroud)
但是如何排除包含string1或的行string2.
Eri*_*ski 95
把它放进去filename.txt:
abc
def
ghi
jkl
Run Code Online (Sandbox Code Playgroud)
grep命令使用-E选项,在字符串中的标记之间使用管道:
grep -Ev 'def|jkl' filename.txt
Run Code Online (Sandbox Code Playgroud)
打印:
abc
ghi
Run Code Online (Sandbox Code Playgroud)
使用-v选项的命令,其中包含由parens包围的标记之间的管道:
egrep -v '(def|jkl)' filename.txt
Run Code Online (Sandbox Code Playgroud)
打印:
abc
ghi
Run Code Online (Sandbox Code Playgroud)
rez*_*ter 35
另一种选择是创建一个排除列表,当您有一长串需要排除的内容时,这是特别有用的.
vi /root/scripts/exclude_list.txt
Run Code Online (Sandbox Code Playgroud)
现在添加您要排除的内容
Nopaging the limit is
keyword to remove is
Run Code Online (Sandbox Code Playgroud)
现在使用grep从文件日志文件中删除行并查看未排除的信息.
grep -v -f /root/scripts/exclude_list.txt /var/log/admin.log
Run Code Online (Sandbox Code Playgroud)
wis*_*cky 35
grep -Fv -e 'Nopaging the limit is' -e 'keyword to remove is'
Run Code Online (Sandbox Code Playgroud)
-F 按文字字符串匹配(而不是正则表达式)
-v 反转比赛
-e 允许多种搜索模式(所有文字和倒置)
Ste*_*ski 21
egrep -v "Nopaging the limit is|keyword to remove is"
Run Code Online (Sandbox Code Playgroud)
hs.*_*dra 12
tail -f admin.log|grep -v -E '(Nopaging the limit is|keyword to remove is)'
Run Code Online (Sandbox Code Playgroud)
mik*_*ail 10
您可以像这样使用常规grep:
tail -f admin.log | grep -v "Nopaging the limit is\|keyword to remove is"
greps可以链接.例如:
tail -f admin.log | grep -v "Nopaging the limit is" | grep -v "keyword to remove is"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
111778 次 |
| 最近记录: |