regex – 使用grep或sed从日志中提取电子邮件地址
发布时间:2020-12-14 01:28:48 所属栏目:Linux 来源:网络整理
导读:Jan 23 00:46:24 portal postfix/smtp[31481]: 1B1653FEA1: to=wanted1918_ke@yahoo.com,relay=mta5.am0.yahoodns.net[98.138.112.35]:25,delay=5.4,delays=0.02/3.2/0.97/1.1,dsn=5.0.0,status=bounced (host mta5.am0.yahoodns.net[98.138.112.35] said: 5
Jan 23 00:46:24 portal postfix/smtp[31481]: 1B1653FEA1: to=<wanted1918_ke@yahoo.com>,relay=mta5.am0.yahoodns.net[98.138.112.35]:25,delay=5.4,delays=0.02/3.2/0.97/1.1,dsn=5.0.0,status=bounced (host mta5.am0.yahoodns.net[98.138.112.35] said: 554 delivery error: dd This user doesn't have a yahoo.com account (wanted1918_ke@yahoo.com) [0] - mta1321.mail.ne1.yahoo.com (in reply to end of DATA command)) Jan 23 00:46:24 portal postfix/smtp[31539]: AF40C3FE99: to=<devi_joshi@yahoo.com>,relay=mta7.am0.yahoodns.net[98.136.217.202]:25,delay=5.9,delays=0.01/3.1/0.99/1.8,status=bounced (host mta7.am0.yahoodns.net[98.136.217.202] said: 554 delivery error: dd This user doesn't have a yahoo.com account (devi_joshi@yahoo.com) [0] - mta1397.mail.gq1.yahoo.com (in reply to end of DATA command)) 从上面的maillog我想提取括号之间的电子邮件地址< ...>例如.到= LT; wanted1918_ke@yahoo.comu0026gt;想要1918_ke@yahoo.com 我正在使用cut -d” – f7来提取电子邮件,但我很好奇是否有更灵活的方式. 解决方法
使用GNU grep,只需使用包含外观的正则表达式并向前看:
$grep -Po '(?<=to=<).*(?=>)' file wanted1918_ke@yahoo.com devi_joshi@yahoo.com 这说:嘿,提取前面的所有字符串to =<然后是>. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |