gpt4 book ai didi

linux - Bash 从匹配特定文本的行的输出中排除一行

转载 作者:太空宇宙 更新时间:2023-11-04 09:34:47 25 4
gpt4 key购买 nike

我想创建一个 cronjob,如果某个目录通过扫描日志文件发送了一定数量的电子邮件,它会提醒我们。我正在使用的一个类轮是:

awk '$3 ~ /^cwd/{print $3}' /var/log/exim_mainlog | sort | uniq -c | sed "s|^ *||g" | sort -nr | head --lines 5

在我进一步了解之前,我需要从输出中排除一些位置,例如:

50992 cwd=/var/spool/exim
21960 cwd=/home/USER1/public_html/wp-content/cache/object/000000/746
2717 cwd=/etc/csf
2063 cwd=/home/USER2
1072 cwd=/

我需要排除:

1072 cwd=/
2717 cwd=/etc/csf
50992 cwd=/var/spool/exim

我需要将输出附加到 txt 文件然后使用 SED 还是有更简单的方法?

最佳答案

通过 grep -v 排除匹配:

egrep -v ' cwd=(/$|/etc/csf|/var/spool/exim)'

关于linux - Bash 从匹配特定文本的行的输出中排除一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27830091/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com