是的,所以我输入的文件有很多行,但我只对$11
和$12
感兴趣。
这些字段如下所示:
$ 11
7.4ms
8.5ms
11.6ms
港币$ 96
TelegramHandlerPackingInfeedHanging
TelegramHandlerPackingOrderBufferHanging
在$12
内,有10个不同的值。
我有以下代码,它返回这10个值以及我需要的一些输出。
#!/usr/bin/gawk -f
BEGIN {
print "Testing glly"
} #End of BEGIN
{ #Start of MID
MSG_TYPE[substr($12,match($12,":")+1,match($12,")")-15)]++;
TIME_AR[$11]++;
SUM[i++] += $11;
} #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
我想要做的是你可能已经注意到我还有两个阵列,TIME_AR
和SUM
。我的问题是如何修改当前脚本以返回10个不同值的单个段,但是给出数组SUM
中值的总和?我试图这样做,但它为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)
答案 0 :(得分:2)
这或多或少看起来像你想要的。您的代码使用了错误的值作为数组的索引。
#!/usr/bin/gawk -f
{
key = substr($12,match($12,":")+1,match($12,")")-15)
MSG_TYPE[key]++
TIME_AR[key] += $11
}
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