# License : http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en
# Author:   Jeong Han Lee
# email :   jeonghan 'dot' lee 'at' gmail 'dot' com
# Date:     Thursday, August 19 10:39:49 EDT 2010
# Version:  0.0.1
#
#          This script can calculate a running mean, a sample deviation
#          , and a standard deviation from xterm output.
#
# History:
# 0.0.1     Thursday, August 19 10:41:44 EDT 2010  
#          
#


# How to use.....
# $4 is what interests me.
# For example,
# ps aux | grep jhlee | awk '{print $2} '
# 20488
# 20490
# 20528
# 20544
# 20674
# 20805
# 20806
# 20807
# 23841

# then $4 is replaced by $2, then
# ps aux | grep jhlee | awk -f average.awk
# Total count        : 52
# mean               : 10966.7
# Sample Deviation   : 8159.65
# Standard Deviation : 8080.81

# Tuesday, August 17 11:17:02 EDT 2010, jhlee
#awk ' {print "  CPU " $2 " "$3 " " $4 " " $5 " " $6 " s per event)" }'

BEGIN {
    count = 0
    mean0 = 0
    sd0   = 0
    sample_deviation = 0
    standard_deviation = 0
}

{
    x = $4
    count += 1
    #    totalsize += x
    indexI1 = x
    mean1   = mean0 +1/count * ( x - mean0 )
    sd1     = sd0 + ( x - mean0 )*( x - mean1 )
    mean0   = mean1
    sd0     = sd1
    if (count !=0 && sd0 != 0) {
    sample_deviation   = sqrt(1/(count-1)*sd0)
    standard_deviation = sqrt(1/count*sd0)
    }
}

END {
    printf "Total count        : %8d\n", count
    #   print "average size = " totalsize/count
    printf "Mean               : %8.2lf\n", mean0
    printf "Sample Deviation   : %8.2lf\n", sample_deviation
    printf "Standard Deviation : %8.2lf\n", standard_deviation

}


Result

grep -r CPU ~/QwAnalysis/trunk/ou-qweak.20100817.00.* | awk -f average.awk

Total count        : 20
mean : +- [ sample deviation, standard deviation]
mean :   748.65 +- [    60.40,    58.87 ] s



references

저작자 표시 비영리 변경 금지
신고

'Computer > linux' 카테고리의 다른 글

strtok을 사용하지 말자.  (0) 2010.08.24
awk with a running average and sample deviation  (0) 2010.08.18
emacs 한글 폰트 및 한글 입력  (0) 2010.07.22
google code  (0) 2010.07.21
posted by citadel

When I kill all processes of the firefox,

ps aux |grep -r firefox | awk '{print $2}' | xargs kill -9
신고
posted by citadel
histogram.dat has the following structure:
-100 -99 7
-99 -98 8
-98 -97 11
-97 -96 10
-96 -95 4
-95 -94 6
-94 -93 11
-93 -92 13
-92 -91 11

I want to change "histogram.dat" to the below structure:
-100 7
-99 7
-99 8
-98 8
-98 11
-97 11
-97 10
-96 10
-96 4
-95 4
-95 6
-94 6
-94 11
-93 11
-93 13
-92 13
-92 11

 awk '{print $1, $3 ; print $2, $3}' histogram.dat > histogram2.dat
신고
posted by citadel
awk