I am using sed regex to extract some information from a log file in order to use it further for analysis. I created a below command but it wont works for me.
sed -e 's/\([0-9] [0-9]*.[0-9]*.[0-9]*\)[^@]* ([^@]*@[^[:spa
ce:]]*).*F=<\([^ ]*\)>.*I=[\([0-9]\+\.[0-9]\+\.)].*$/\1\t\2/' logs
Logs:
2017-02-13 10:31:55 1cd9Ev-003XiE-Sx ** [email protected] F=<[email protected]> R=dkim_lookuphost T=dkim_remote_smtp H=ah2.inboundmx.com [216.82.242.115] I=[147.75.228.64] X=TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256 CV=yes DN="/C=US/ST=California/L=Mountain View/O=Symantec Corporation/OU=Symantec.cloud CN=mail132.messagelabs.com": SMTP error from remote mail server after end of data: 553-Message filtered. Refer to the Troubleshooting page at\n553-http://www.symanteccloud.com/troubleshooting for more\n553 information. (#5.7.1)
2017-02-14 10:01:40 1cd9Ev-003XiE-Sx ** [email protected] F=<[email protected]> R=dkim_lookuphost T=dkim_remote_smtp H=ah2.inboundmx.com [216.82.242.115] I=[14.176.22.221] X=TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256 CV=yes DN="/C=US/ST=California/L=Mountain View/O=Symantec Corporation/OU=Symantec.cloud CN=mail132.messagelabs.com": 501 Connection rejected by policy. Refer to the Troubleshooting page at\n501-http://www.symanteccloud.com/troubleshooting for more\n501 information. (#5.7.1)
I wanted to extract the following fields from above logs:
Timestamp EmailTo: EmailFrom: IPAddress: ErrorCodes:
2017-02-13 10:31:55 [email protected] [email protected] 147.75.228.64 553
2017-02-14 10:01:40 [email protected] [email protected] 14.176.22.221 501
awk '{t=$0;sub(/.*\\n/, "", t);sub(/ .*/, "", t);print $1, $2, $5, substr($6, 4, length($6)-4), substr($11, 4, length($11)-4), t}'... thet, sub, subextracts the error code, the rest is self-explanatory - print the respective fields except for$6and$11where it extracts only part of the field and prints the result