Calculate Average time of a column
Hello dears,
I have a log file with records like below and want to get a average of one column based on the search of one specific keyword. 2015-02-07 08:15:28 10.102.51.100 10.112.55.101 "kevin.c" POST /mainportal/webflow/customerprofile/smsEmailNotications/loadSubCategories.do?&msisdn=374355752&categoryCode=GSM_19 0.391 200 1740 suppose keyword is "loadSubCategories" and response time is on "column 8" (0.391) This command gives a average of all response time of column 8 but not with the given keyword. awk '{ total += $8; count++ } END { print total/count }' file.log001 please let me know how to write it. Thanks. |
> This command gives a average of all response time of column 8 but not with the given keyword.
Which command did you mean? |
Sorry,post edited...
|
I presume $6 has the key word.
So change it to awk '{ if($6=="loadSubcategories") {total += $8; count++} } END { print total/count }' file.log001 OK |
Or ... and I'm serious ... just slurp it into a spreadsheet and ask for sum(). Solved. :)
|
hmmm ... not sure how AnanthaP's solution would work as the sixth field is not equal to that string??
However, the logic is similar to what you already have, just tell awk to only add up the eighth column when your line contains the string required, ie. look up the use of // |
It doesn't work with == as the keyword is a part of the string!
how to replace the the equal sign with like command? |
Code:
awk '{ if (index ($6, "loadSubcategories")) {total += $8; count++} } END { print total/count }' file.log001 |
Thank You everybody for your help.
Below script also seems works correctly... awk '/loadSubcategories/ {total += $8; count++} END { print total/count }' access.log00001 |
Quote:
|
All times are GMT -5. The time now is 08:21 PM. |