grep - Grep 匹配模式但排除特定字符串
问题描述
我有包含各种日志行的文件,我想要grep
一个模式但排除 when message:com.mycompany.excluded
,所以基本上应该返回以下内容:
"The log found this message blah, message:com.blahblah"
"The log found this message blah2, message:com.blahblah2"
"The log found this message foobar, message:com.mycompany"
"The log found this message blah, message:com.mycompany.included"
但不是 :
"The log found this message blah, message:com.mycompany.excluded"
我正在使用这种模式,但它不适用于排除com.mycompany.excluded
grep "The log found this message.*message:.*" "mylogs.txt"
解决方案
awk '/The log found this message.*message:/ && !/com.mycompany.excluded/' "mylogs.txt"
有多种方法可以使它更健壮,但它们可能不是必需的(取决于日志文件的其余部分)。
推荐阅读
- java - .jdbc4.MySQLIntegrityConstraintViolationException:Spring JPA 中针对@Column 的重复条目(unique = true)
- django - Django dumpdata CommandError:无法序列化数据库:int() 的无效文字,基数为 10
- javascript - java脚本下拉控件(多选)上的可访问性(ADA)编码挑战
- javascript - 表达式如何在来自 sessionStorage 的错误条件下计算为真?
- node.js - 如何在函数内部使用 Visual Studio Code 调试 Node.js?
- python - 人名的python正则表达式
- c - 为什么这段代码运行仍然有效,有 '&' 或没有 '&'?
- vba - MS-Access 模态表单而不是消息框
- pandas - 如何在多个列上透视表和聚合?
- python - 如何在多个 Celery 任务中结合实施 Prometheus 监控?