I have extracted the following information from the raw logs below using this command:
echo -e "Timestamp\t\tEmailTo:\t\tEmailFrom:\t\t\t\t\tIPAddress:\tErrorCodes:" && sed -n -e 's/.*\([0-9][0-9][0-9][0-9]\-[0-9][0-9]\-[0-9]*\) .*\([0-9][0-9]:[0-9][0-9]:[0-9][0-9]*\).*/\1 \2 /p' logs
Output:
Timestamp EmailTo: EmailFrom: IPAddress: ErrorCodes:
2017-01-02 12:50:00
2017-01-02 13:10:25
Raw logs:
2017-01-02 12:50:00 1cNxNS-001NKu-9B == [email protected] R=dkim_lookuphost T=dkim_remote_smtp defer (-45) H=mta6.am0.yahoodns.net [98.138.112.38]: SMTP error from remote mail server after MAIL FROM:<[email protected]> SIZE=1772: 421 4.7.0 [TSS04] Messages from 192.168.1.269 temporarily deferred due to user complaints - 4.16.55.1; see https://help.yahoo.com/kb/postmaster/SLN3434.html
2017-01-02 13:10:25 1cNxhD-001VZ3-0f == [email protected] ([email protected]) <[email protected]> R=lookuphost T=remote_smtp defer (-45) H=mta7.am0.yahoodns.net [98.138.112.34]: SMTP error from remote mail server after MAIL FROM:<[email protected]> SIZE=87839: 500 5.9.0 [TSS04] Messages from 192.168.1.269 temporarily deferred due to user complaints - 4.16.55.1; see https://help.yahoo.com/kb/postmaster/SLN3434.html
But I am unable to extract the other information I need; it should looks like:
Timestamp EmailTo: mailFrom: IPAddress: ErrorCodes:
2017-01-02 12:50:00 [email protected] [email protected] 192.168.1.269 421 4.7.0
2017-01-02 13:10:25 [email protected] [email protected] 192.168.1.269 500 5.9.0
How can I extract all the information using sed?
sedpatterns? You just need to extend your current pattern to match the information you need, and not just the first two pieces.sed -n 's/.*\([0-9][0-9][0-9][0-9]\-[0-9][0-9]\-[0-9]*\) .*\([0-9][0-9]:[0-9][0-9]:[0-9][0-9]*\) .\^([^==]\[A-Z0-9._%-+]\@[A-Z0-9.-]\.[A-Z]{2,4}*\).*/\1 \2 \3 /p' exim_logs