sat*_*gie 4 regex awk grep cut sed
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, dsn=5.0.0, 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))
Run Code Online (Sandbox Code Playgroud)
从上面的maillog我想提取括在角括号之间的电子邮件地址,< ... >例如.to=<wanted1918_ke@yahoo.com>至wanted1918_ke@yahoo.com
我正在使用cut -d' ' -f7提取电子邮件,但我很好奇是否有更灵活的方式.
使用GNU grep,只需使用包含外观的正则表达式并向前看:
$ grep -Po '(?<=to=<).*(?=>)' file
wanted1918_ke@yahoo.com
devi_joshi@yahoo.com
Run Code Online (Sandbox Code Playgroud)
这说:嘿,提取所有前面to=<和后面的字符串>.