We have a big file in which three columns are there that is hour, response time and service name. These fields are separated by space. We need write a script to calculate the number of occurrence of the service name on an hourly basis and find the average of response time. A piece of file is shown below. 15 999 createLead15 999 getLead15 999 jointCall15 999 searchLead16 1002 jointCall16 1019 createLead16 1031 jointCall16 1032 jointCall16 1040 jointCall16 1044 jointCall17 1011 createLead17 1027 createLead17 189 getLTSUserDetails19 1439 searchLead19 1708 searchFileStatus19 1832 updateLead
script to calculate the average
text processing
awkawk '    {    task[$3,$1] += $2    count[$3,$1] += 1    }    END {        for (t in task) {            split(t, tHour, \034);            print tHour[1]   tHour[2]   count[t]   task[t] / count[t]        }    }' yourFileResultTask, Hour, Num of occurrence, Average of response timesearchFileStatus 19 1 1708searchLead 19 1 1439getLead 15 1 999jointCall 15 1 999jointCall 16 5 1029.8updateLead 19 1 1832createLead 15 1 999createLead 16 1 1019getLTSUserDetails 17 1 189createLead 17 2 1019searchLead 15 1 999Previous attempt:awkawk '    {    task[$3] += $2    count[$3] += 1    }    END {        for (t in task) {            print t   count[t]   task[t] / count[t]        }    }' yourFileResultTask, Num of occurrence, Average of response timeupdateLead 1 1832jointCall 6 1024.67getLead 1 999getLTSUserDetails 1 189createLead 4 1014searchLead 2 1219searchFileStatus 1 1708