加入收藏 | 设为首页 | 会员中心 | 我要投稿 云计算网_宿迁站长网 (https://www.0527zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

linux – 在tail -f中,如何过滤掉具有某些关键字的内容?

发布时间:2020-12-24 20:32:26 所属栏目:Linux 来源:网络整理
导读:我想尾随我的日志.但是,我想过滤掉所有包含这些词语的内容: “ELB”,“Pingdom”,“健康” 解决方法 我不知道使用awk而不是grep,但这对我有用: tail -f file.log | grep -Ev '(ELB|Pingdom|Health)' 编辑:正如dmourati和Caleb所指出的那样,为方便起见,

我想尾随我的日志.但是,我想过滤掉所有包含这些词语的内容:

“ELB”,“Pingdom”,“健康”

解决方法

我不知道使用awk而不是grep,但这对我有用:
tail -f file.log | grep -Ev '(ELB|Pingdom|Health)'

编辑:正如dmourati和Caleb所指出的那样,为方便起见,您也可以使用egrep而不是grep -E.在某些系统上,这将是指向同一二进制文件的链接,而在其他系统中则是由grep包提供的副本.无论哪种方式,它都可以作为-E开关的替代品.但是,根据GNU grep手册页:

[…]two variant programs egrep and fgrep are available. egrep is the same as grep -E. fgrep is the same as grep -F. Direct invocation as either egrep or fgrep is deprecated,but is provided to allow historical applications that rely on them to run unmodified.

因为它们是同义命令,所以除非你根本没有egrep,否则它归结为偏好.但是为了向前兼容,建议使用grep -E语法,因为其他方法已被正式弃用.

(编辑:云计算网_宿迁站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!