ログ抽出

ログ抽出

問題は、このコマンドを実行したときに完全なIPアドレスが表示されないことです137.244.209.141。この情報を正しく抽出する方法は?

ランダムログ:

2016-08-08 14:24:24 [480879] 1bWgnG-00215x-Li ** [email protected] F=<[email protected]> P=<[email protected]> R=lookuphost T=remote_smtp H=mx3.hotmail.com [65.55.33.119]:25 I=[137.244.209.141]:32899 X=TLSv1.2:ECDHE-RSA-AES256-SHA384:256 CV=yes DN="/CN=*.hotmail.com": SMTP error from remote mail server after MAIL FROM:<[email protected]> SIZE=52485: 550 SC-001 (COL004-MC5F14) Unfortunately, messages from 137.244.209.141 weren't sent. Please contact your Internet service provider since part of their network is on our block list. You can also refer your provider to http://mail.live.com/mail/troubleshooting.aspx#errors.
2016-08-08 14:24:38 [481047] 1bWgnT-00211m-SS ** [email protected] ([email protected]) <[email protected]> F=<[email protected]> P=<[email protected]> R=lookuphost T=remote_smtp H=mx3.hotmail.com [65.54.188.72]:25 I=[137.244.209.141]:59328 X=TLSv1.2:ECDHE-RSA-AES256-SHA384:256 CV=yes DN="/CN=*.hotmail.com": SMTP error from remote mail server after MAIL FROM:<[email protected]> SIZE=19825: 550 SC-001 (BAY004-MC1F33) Unfortunately, messages from 137.244.209.141 weren't sent. Please contact your Internet service provider since part of their network is on our block list. You can also refer your provider to http://mail.live.com/mail/troubleshooting.aspx#errors.

ログからデータを抽出するコマンド:

sed -nE 's,^([-0-9]{10})[^@]* ([^@]*@[^[:space:]]*)[^=]*F=<([^@]*@[^[:space:]]*)>.*SIZE=[^[:space:]]* (... ..-...) .*([[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+).*,\1    \2    \3  \5    \4,p' logs | column -t

出力:

2016-08-08  [email protected]   [email protected]          7.244.209.141  550  SC-001
2016-08-08  [email protected]  [email protected]  7.244.209.141  550  SC-001

ベストアンサー1

問題は、IPアドレスの一致の前のエントリが貪欲であるため、.*文字列内でできるだけ一致することです。

.*([[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+).*,

.*数字の境界で停止するには、最初のものを修正する必要があります。私が提案するこれはうまくいくかもしれませんが、サンプルデータに対してのみexim4テストしました。

.*[^[:digit:]]

修正された出力

2016-08-08  [email protected]   [email protected]          137.244.209.141  550  SC-001
2016-08-08  [email protected]  [email protected]  137.244.209.141  550  SC-001

おすすめ記事