我有一个 csv 文件,我需要过滤标有“垃圾邮件”字样的邮件,如下所示
email;text;somestatus;mailserver status response; response message
[email protected];mx.mail.com;2;connection reset; try later
[email protected];somemx.record.com;3;spam message response; connection reset
[email protected];spammxrecord.com;5;Deferred: lsjdflsdj; try later
[email protected];mx-too.de., dsn=4.0.0, stat=Deferred: Connection reset by mx-too.de.;4;Deferred: Connection reset by mx-too.de.
第 3 行和第 5 行应该匹配
如果在第一个 csv 部分(直到第一个 ';' 的字符)中包含单词 'spam',则该模式应该匹配;如果该单词在 csv 的其他列中,则它不应该匹配
我尝试过
grep -e "spam[^;]*;\([^;]*;\)\{3\}"
有人知道解决办法吗?谢谢
答案1
尝试grep -e "^[^;]*spam[^;]*;"