-1

Right so I have and input file which has a multitude of rows but I am only interested in $11 and $12.

these fields look like the following:

$11

 7.4ms 
 8.5ms 
 11.6ms

$12

TelegramHandlerPackingInfeedHanging
TelegramHandlerPackingOrderBufferHanging

Within $12 there are 10 distinct values.

I have the following Code which is returning these 10 values as well as some out puts that I need.

#!/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

The out put I am getting so far looks like the following:

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

What I am trying to do is you may have noticed that I have 2 more arrays, TIME_AR and SUM. My question is how can I modify my current script to return a single segment for the 10 distinct values but give me a total sum of the values in the array SUM? I have tried to do this but it is returning 10 segments for each of the 10 distinct values.

Thanks in advance.

Reduced while still providing information.

Sorry, sample Input is as follows:

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)
glly
  • 107
  • 7
  • edit your Q to show what your required output is, given your inputs. (I didn't downvote). Good luck. – shellter Jun 17 '16 at 01:22
  • and while this Q is a big improvement over your previous, you shouldn't expect people to "detect" where your problem is. There is still too much data and sample output. Can't you reduce this to 1-2 good records that should be processed (and if appropriate) 1-2 records that shouldn't be processed? You say `$12` has 10 distinct values. If you knew how to solve it for 3, wouldn't that be all you need to generalize for any number of values? Reduce, reduce, reduce, ... . But Good luck ;-) ! – shellter Jun 17 '16 at 01:25
  • Without sample input, I can't test a solution I'm confident putting into an answer. So .. while many of us could probably solve this problem, we *won't* because we can't be sure we're right. – ghoti Jun 17 '16 at 02:00
  • @ghoti I have added a sample of the input file that I am using. – glly Jun 17 '16 at 02:18
  • Don't use all upper case for variable names as they can clash with builtin names and obfuscate your code by making it look like that's what they are. When posting a question show both sample input AND the output you want to get given that input. That's just part of creating a [mcve] which is the starting point of asking for help, see [ask]. – Ed Morton Jun 17 '16 at 04:32

1 Answers1

2

This looks like more or less what you want. Your code is using the wrong value as the index to the arrays.

#!/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"
    }
}

Extended data

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)

Output from extended data

TelegramHandlerPackingInfeedHanging
Message Count: 3
AVG: 56.5667ms
TelegramHandlerTUNotification
Message Count: 2
AVG: 9189.4ms
TelegramHandlerPackingOrderBufferHanging
Message Count: 1
AVG: 26.8ms
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278