AWK - 调用多个数组

AWK - Calling multiple arrays

是的,所以我输入了很多行的文件,但我只对 </code> 和 <code>.

感兴趣

这些字段如下所示:

11美元

 7.4ms 
 8.5ms 
 11.6ms

$12

TelegramHandlerPackingInfeedHanging
TelegramHandlerPackingOrderBufferHanging

</code> 中有 10 个不同的值。</p> <p>我有以下代码 returning 这 10 个值以及我需要的一些输出。</p> <pre><code>#!/usr/bin/gawk -f BEGIN { print "Testing glly" } #End of BEGIN { #Start of MID MSG_TYPE[substr(,match(,":")+1,match(,")")-15)]++; TIME_AR[]++; SUM[i++] += ; } #End of MID END { for (MSG in MSG_TYPE) { print MSG print "Message Count: "MSG_TYPE[MSG] print "MIN: " print "MAX: " print "Total MSG: "MSG_TYPE[MSG] print "AVG: "SUM[sum]/MSG_TYPE[MSG]"ms" } } #End of END

到目前为止我得到的输出如下所示:

Testing glly
TelegramHandlerPackingInfeedHanging
Message Count: 65128
MIN:
MAX:
Total MSG: 65128
AVG: 0ms
TelegramHandlerPackingOrderBufferHanging
Message Count: 68473
MIN:
MAX:
Total MSG: 68473
AVG: 0ms

我想做的是您可能已经注意到我还有 2 个数组,TIME_ARSUM。我的问题是如何将当前脚本修改为 return 10 个不同值的单个段,但给我数组 SUM 中值的总和?我曾尝试这样做,但它 return 为 10 个不同的值中的每一个设置了 10 个段。

提前致谢。

减少但仍提供信息。

抱歉,示例输入如下:

INFO  2016-06-15 00:00:28.273 TelegramDispatcher                                       - --> Complete telegram dispatching took 11189.4ms (canHandle(69:TelegramHandlerTUNotification) took 0.0ms, handleTelegram took 11182.0ms, commit took 5.1ms, doACK took 1.8ms, doNAK took -0.0ms performAfterCommit took 0.3ms, failedCanHandle took 0.1ms)
INFO  2016-06-15 00:00:28.531 TelegramDispatcher                                       - --> Complete telegram dispatching took 58.5ms (canHandle(60:TelegramHandlerPackingInfeedHanging) took 0.0ms, handleTelegram took 43.5ms, commit took 13.0ms, doACK took 1.4ms, doNAK took -0.0ms performAfterCommit took 0.3ms, failedCanHandle took 0.1ms)
INFO  2016-06-15 00:00:28.558 TelegramDispatcher                                       - --> Complete telegram dispatching took 26.8ms (canHandle(61:TelegramHandlerPackingOrderBufferHanging) took 0.0ms, handleTelegram took 10.5ms, commit took 14.5ms, doACK took 1.2ms, doNAK took -0.0ms performAfterCommit took 0.4ms, failedCanHandle took 0.1ms)

这看起来或多或少是您想要的。您的代码使用了错误的值作为数组的索引。

#!/usr/bin/gawk -f

{
    key = substr(,match(,":")+1,match(,")")-15)
    MSG_TYPE[key]++
    TIME_AR[key] += 
}
END {
    for (MSG in MSG_TYPE)
    {
        print MSG
        print "Message Count: " MSG_TYPE[MSG]
        print "AVG: " TIME_AR[MSG]/MSG_TYPE[MSG] "ms"
    }
}

扩展数据

INFO  2016-06-15 00:00:28.273 TelegramDispatcher        - --> Complete telegram dispatching took 11189.4ms (canHandle(69:TelegramHandlerTUNotification) took 0.0ms, handleTelegram took 11182.0ms, commit took 5.1ms, doACK took 1.8ms, doNAK took -0.0ms performAfterCommit took 0.3ms, failedCanHandle took 0.1ms)
INFO  2016-06-15 00:00:28.273 TelegramDispatcher        - --> Complete telegram dispatching took 7189.4ms (canHandle(69:TelegramHandlerTUNotification) took 0.0ms, handleTelegram took 11182.0ms, commit took 5.1ms, doACK took 1.8ms, doNAK took -0.0ms performAfterCommit took 0.3ms, failedCanHandle took 0.1ms)
INFO  2016-06-15 00:00:28.531 TelegramDispatcher        - --> Complete telegram dispatching took 58.5ms (canHandle(60:TelegramHandlerPackingInfeedHanging) took 0.0ms, handleTelegram took 43.5ms, commit took 13.0ms, doACK took 1.4ms, doNAK took -0.0ms performAfterCommit took 0.3ms, failedCanHandle took 0.1ms)
INFO  2016-06-15 00:00:28.531 TelegramDispatcher        - --> Complete telegram dispatching took 48.5ms (canHandle(60:TelegramHandlerPackingInfeedHanging) took 0.0ms, handleTelegram took 43.5ms, commit took 13.0ms, doACK took 1.4ms, doNAK took -0.0ms performAfterCommit took 0.3ms, failedCanHandle took 0.1ms)
INFO  2016-06-15 00:00:28.531 TelegramDispatcher        - --> Complete telegram dispatching took 62.7ms (canHandle(60:TelegramHandlerPackingInfeedHanging) took 0.0ms, handleTelegram took 43.5ms, commit took 13.0ms, doACK took 1.4ms, doNAK took -0.0ms performAfterCommit took 0.3ms, failedCanHandle took 0.1ms)
INFO  2016-06-15 00:00:28.558 TelegramDispatcher        - --> Complete telegram dispatching took 26.8ms (canHandle(61:TelegramHandlerPackingOrderBufferHanging) took 0.0ms, handleTelegram took 10.5ms, commit took 14.5ms, doACK took 1.2ms, doNAK took -0.0ms performAfterCommit took 0.4ms, failedCanHandle took 0.1ms)

扩展数据的输出

TelegramHandlerPackingInfeedHanging
Message Count: 3
AVG: 56.5667ms
TelegramHandlerTUNotification
Message Count: 2
AVG: 9189.4ms
TelegramHandlerPackingOrderBufferHanging
Message Count: 1
AVG: 26.8ms