【问题标题】:Parsing log entries using awk使用 awk 解析日志条目
【发布时间】:2013-11-26 21:14:03
【问题描述】:

我得到以下日志:

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$

【问题讨论】:

  • 欢迎来到 Stack Overflow。请尽快阅读About 页面。传入记录是否在 3 行上?您希望$Province$$Region Name$ 出现在输出中吗?输入包含“区域帐户”但输出包含“客户帐户”是偶然还是故意的。 'Manila Olongapo Leyte Tacloban' 列表是否有所不同?
  • 如果 $Region Name$ 或 $Province$ 不遵循与您示例中相同数量的字段,您想要的此日志解析器将失败。请使用更准确的要求编辑您的问题。

标签: parsing awk


【解决方案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)}'

【讨论】:

    【解决方案2】:

    这在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
    

    【讨论】:

    • OP 询问的是 awk,而不是 sed。
    猜你喜欢
    • 2012-04-20
    • 1970-01-01
    • 2021-04-24
    • 1970-01-01
    • 2020-09-13
    • 2017-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多