awk script to count percentage from log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk script to count percentage from log file
# 1  
Old 05-07-2009
Question awk script to count percentage from log file

Hi,

I have a log like this :

Quote:
Object Counter 12:00 12:15 12:30 12:45
30011 pmTotNoRrcConnectReq 71 65 82 70
30011 pmTotNoRrcConnectReqSuccess 71 64 84 70
30012 pmTotNoRrcConnectReq 109 104 112 125
30012 pmTotNoRrcConnectReqSuccess 109 104 112 124
30013 pmTotNoRrcConnectReq 66 64 67 63
30013 pmTotNoRrcConnectReqSuccess 66 64 67 63
30021 pmTotNoRrcConnectReq 139 123 141 149
30021 pmTotNoRrcConnectReqSuccess 139 123 140 149
30022 pmTotNoRrcConnectReq 69 62 83 67
30022 pmTotNoRrcConnectReqSuccess 69 62 84 67
30023 pmTotNoRrcConnectReq 43 66 64 59
30023 pmTotNoRrcConnectReqSuccess 42 66 65 59
30031 pmTotNoRrcConnectReq 409 421 415 418
30031 pmTotNoRrcConnectReqSuccess 410 425 409 417
30032 pmTotNoRrcConnectReq 61 112 89 61
30032 pmTotNoRrcConnectReqSuccess 61 112 87 61
30033 pmTotNoRrcConnectReq 266 281 324 299
30033 pmTotNoRrcConnectReqSuccess 262 280 323 296
30041 pmTotNoRrcConnectReq 44 39 50 41
30041 pmTotNoRrcConnectReqSuccess 44 38 51 41
30042 pmTotNoRrcConnectReq 113 98 119 91
30042 pmTotNoRrcConnectReqSuccess 113 98 116 92
30043 pmTotNoRrcConnectReq 108 116 132 105
30043 pmTotNoRrcConnectReqSuccess 108 115 132 102
30051 pmTotNoRrcConnectReq 194 230 211 200
30051 pmTotNoRrcConnectReqSuccess 194 230 210 199
30052 pmTotNoRrcConnectReq 199 190 177 201
30052 pmTotNoRrcConnectReqSuccess 198 191 177 198
30053 pmTotNoRrcConnectReq 183 203 179 201
30053 pmTotNoRrcConnectReqSuccess 183 201 179 201
30061 pmTotNoRrcConnectReq 468 463 413 435
30061 pmTotNoRrcConnectReqSuccess 468 462 411 435
30062 pmTotNoRrcConnectReq 617 501 555 539
30062 pmTotNoRrcConnectReqSuccess 615 504 553 539
30063 pmTotNoRrcConnectReq 182 204 189 186
30063 pmTotNoRrcConnectReqSuccess 179 207 188 184
30071 pmTotNoRrcConnectReq 434 451 385 324
30071 pmTotNoRrcConnectReqSuccess 431 440 379 323
30072 pmTotNoRrcConnectReq 140 139 122 134
30072 pmTotNoRrcConnectReqSuccess 140 139 122 134
30073 pmTotNoRrcConnectReq 495 505 441 449
30073 pmTotNoRrcConnectReqSuccess 495 496 437 449
30081 pmTotNoRrcConnectReq 881 957 1014 927
30081 pmTotNoRrcConnectReqSuccess 877 953 1013 926
30082 pmTotNoRrcConnectReq 0 0 0 0
30082 pmTotNoRrcConnectReqSuccess 0 0 0 0
30083 pmTotNoRrcConnectReq 0 0 0 0
30083 pmTotNoRrcConnectReqSuccess 0 0 0 0
30091 pmTotNoRrcConnectReq 434 329 347 283
30091 pmTotNoRrcConnectReqSuccess 432 331 347 281
30092 pmTotNoRrcConnectReq 495 463 465 430
30092 pmTotNoRrcConnectReqSuccess 494 462 466 430
30093 pmTotNoRrcConnectReq 344 339 282 415
30093 pmTotNoRrcConnectReqSuccess 342 339 282 415
30101 pmTotNoRrcConnectReq 92 85 97 76
30101 pmTotNoRrcConnectReqSuccess 91 84 96 75
30102 pmTotNoRrcConnectReq 93 87 108 77
30102 pmTotNoRrcConnectReqSuccess 92 87 108 76
30103 pmTotNoRrcConnectReq 103 91 102 110
30103 pmTotNoRrcConnectReqSuccess 105 92 103 111

actually i want to get the log like this :

Quote:
Object Percentage
------------------------------
30011 xx %
30012 xx %
30013
30021
30022
30023
30031
30032
30033
30041
30042
30043
30051
30052
30053
30061
30062
30063
30071
30072
30073
30081
30082
30083
30091
30092
30093
30101
30102
30103
where % can get from :

100 * pmTotNoRrcConnectReqSucc / pmTotNoRrcConnectReq

Thanks in advance.. Smilie
# 2  
Old 05-07-2009
Can you calc the % for one of them? What is pmTotNoRrcConnectReqSucc and pmTotNoRrcConnectReq for the object 30011 ?
# 3  
Old 05-07-2009
oh yea.. the value for object 30011 for example:
Quote:
30011 pmTotNoRrcConnectReq 71 65 82 70
30011 pmTotNoRrcConnectReqSuccess 71 64 84 70
so it will be :
Quote:
100* (71+64+84+70)/(71+65+82+70
btw can we do it just 1 command line?
# 4  
Old 05-08-2009
if you have Python, here's an alternative solution
Code:
#!/usr/bin/env python
from __future__ import division
d={}
f=open("file")
header=f.readline()
for line in f:        
    line=line.strip().split()
    d.setdefault(line[0],[])
    d[line[0]].append(sum(map(int,line[2:6])))
for i,j in d.iteritems():
    try:
        print i,100*j[1]/j[0]        
    except Exception,e: 
        print e

output:
Code:
# ./test.py
30033 99.2307692308
30032 99.3808049536
30031 99.8797354179
30011 100.347222222
30013 100.0
30012 99.7777777778
30051 99.7604790419
30053 99.7389033943
30052 99.6088657106
30101 98.8571428571
30061 99.8313659359
30062 99.9547920434
30063 99.605781866
30082 float division
30083 float division
30081 99.7353797301
30042 99.5249406176
30043 99.1323210412
30041 100.0
30021 99.8188405797
30022 100.355871886
30023 100.0
30103 101.231527094
30073 99.3121693122
30072 100.0
30071 98.6825595985
30091 99.8564249821
30102 99.4520547945
30093 99.8550724638
30092 99.9460334593

# 5  
Old 05-08-2009
Code:
awk '$0 !~ /Object/{fl=$3+$4+$5+$6;getline;sc=$3+$4+$5+$6;fl=(fl==0)?1:fl;print $1,100*(sc/fl);next}' file

asuuming succ=0 and fl=0 will return 0


cheers,
Devaraj Takhellambam
# 6  
Old 05-08-2009
Code:
nawk '{
if (NR==1)
next
else
for(i=3;i<=6;i++)
_[$1]+=$i
}
END{
print "OBJECT PERCENTAGE"
for(i in _)
	print i" "_[i]/4
}' a.txt

# 7  
Old 05-08-2009
oke thanks all. Smilie
btw for ghostdog74 and devtakh, how to alow just only 2 digit after comma ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

Shell /awk script for Percentage

having two columns, A and B.. i need to add another column C in a file and calculate the percentage based on the column A and B. (COLUMN B/ COLUMN A *100) . "|" is delimiter separating the A and B.. need C column with the percentage value. Thanks for your help 100|50 |50% ... (6 Replies)
Discussion started by: kartikirans
6 Replies

2. Shell Programming and Scripting

awk script to detect specific string in a log file and count it

Hello, can someone guide me on this? I don't know what is the best approach, (awk script, shell script) I am using RedHat Linux version 6.5. There is a third party application deployed on that server. This app by default generates 5 log files and each file is 20MB. These log rollover... (5 Replies)
Discussion started by: ktisbest
5 Replies

3. Shell Programming and Scripting

Help with awk percentage calculation from a file

i have a file say test with the below mentioned details Folder Name Total space Space used /test/test1 500.1GB 112.0 GB /test/test2 3.2 TB 5TB /test/test3 3TB 100GB i need to calculate percentage of each row based on total space and space used and copy... (9 Replies)
Discussion started by: venkitesh
9 Replies

4. Shell Programming and Scripting

Count percentage of string

Hi, Am trying to count the number of occurrences and then as a percentage from a log to troubleshoot errors, can someone help please grep -o 'HTTP/1\.1\" 404 3..' access_log | wc -l 6 (5 Replies)
Discussion started by: dmccabe
5 Replies

5. Shell Programming and Scripting

Awk: Print count for column in a file using awk

Hi, I have the following input in a file & need output as mentioned below(need counter of every occurance of field which is to be increased by 1). Input: 919143110065 919143110065 919143110052 918648846132 919143110012 918648873782 919143110152 919143110152 919143110152... (2 Replies)
Discussion started by: siramitsharma
2 Replies

6. UNIX for Dummies Questions & Answers

Need an awk script to calculate the percentage of value field and replace

I have a input file called file.txt with the following content: john|622.5674603562933|8|br:1;cn:3;fr:1;jp:1;us:2 andy|0.0|12|**:3;br:1;ca:2;de:2;dz:1;fr:2;nl:1 in fourth filed of input file, calulate percentage of each sub filed seperated by ; semicolon and replace value with percentage . i... (11 Replies)
Discussion started by: veeruasu
11 Replies

7. Shell Programming and Scripting

Need an awk script to calculate the percentage of value field and replace

Need an awk script to calculate the percentage of value field and replace I have a input file called file.txt with the following content: john|622.5674603562933|8|br:1;cn:3;fr:1;jp:1;us:2 andy|0.0|12|**:3;br:1;ca:2;de:2;dz:1;fr:2;nl:1 in fourth filed of input file, calulate percentage of each... (1 Reply)
Discussion started by: veeruasu
1 Replies

8. Shell Programming and Scripting

awk script to count characters in file 1 in file 2

I need a scripting AWK to compare 2 files. file 1 and 2 are list of keywords 1 is a b c d 2 is aa aaa b bb ccc d I want the AWK script to give us the number of times every keyword in file 1 occurs in file 2. output should be a 2 (7 Replies)
Discussion started by: anhtt
7 Replies

9. Shell Programming and Scripting

Need an AWK script to calculate the percentage

Hi I need a awk script to calculate percentage. I have to pass the pararmeters in to the awk script and calculate the percentage. Sum = 50 passed = 43 failed = 7 I need to pass these value in to the awk script and calculate the percentage. Please advice me. (8 Replies)
Discussion started by: bobprabhu
8 Replies

10. Shell Programming and Scripting

awk percentage

how would you calculate percentage by per line? Given a column of 16 lines, grab each line and divide it by the sum of the entire column and multiply by 100? thanks ... (8 Replies)
Discussion started by: rockiefx
8 Replies
Login or Register to Ask a Question