使用awk解析日志条目

时间:2013-11-14 01:30:45

标签: parsing awk

我得到以下日志:

2013-10-24 18:35:49,728 ERROR [xx.xx.xx.xx.xx.xx] (xx.xx.xx.xx.xx) Manila Olongapo Leyte Tacloban has updated their subscriber details. But, the Regional Account Update interface call has failed for the following Local Registries: <br/>Visayas<br/>Data between LRA and the above Local Registries is out of synch as a result.

我希望结果输入采用以下格式。有什么更好的方法 - 或许使用awksed?请指教。

$Province$ has updated their subscriber details. However, the Customer Account Update interface call has failed for the following Land Registries:
$Region Name$

2 个答案:

答案 0 :(得分:1)

只考虑你的一行例子,并且只是回答你的问题,这里就是:

echo '2013-10-24 18:35:49,728 ERROR [xx.xx.xx.xx.xx.xx] (xx.xx.xx.xx.xx) Manila Olongapo Leyte Tacloban has updated their subscriber details. But, the Regional Account Update interface call has failed for the following Local Registries: <br/>Visayas<br/>Data between LRA and the above Local Registries is out of synch as a result.'  | awk '{print $6,$7,$8,$9,$10,$11,$12,$13,$14,"However, the Customer",$18,$19,$20,$21,$22,$23,$24,$25,$26,"Land",$28,substr($29,6,7)}'

答案 1 :(得分:0)

sed中很容易做到:

sed -r '
    s#(^.*\) |<br/>Data.*$)##g;
    s/But/However/;
    s/Regional/Customer/;
    s/Local/Land/;
    s# <br/>#\n#
' input.log
Manila Olongapo Leyte Tacloban has updated their subscriber details. However, the Customer Account Update interface call has failed for the following Land Registries:
Visayas