|
|
http://www.reddragonfly.org/abscn/sedawk.html
无故而知新,变化少的东西最值得学
假如日志这样:
2011-07-18 16:38:07,118 <compile template:309648278 Subject 1293>2011-07-18 16:38:08,190 <compile template:309647501 Subject 2176>2011-07-18 16:38:08,235 <compile frag:204186936 1559>2011-07-18 16:38:08,628 <compile template:204186936 Subject 1952>
#!/bin/shecho $1if [ -z "$1" ];thenecho "need one parameter";exit 1;figrep "compile template:.* $1" test/* >hao.txtsed -e "/.*>/ s/\\(\d\\)*>/\\1/" hao.txt >hao1.txt#sed -e "/2011-07-18 15/,/2011-07-18 16/p" hao1.txt >hao.txtawk 'BEGIN{max=0;sum=0;col=0;}{if($6>max){max=$6};sum+=$6;col++}END{print "max="max" sum="sum" avg="sum/col}' hao1.txtexit 1;
每天23:59:00到23:59:59的触发量
#!/bin/shecho $1if [ -z "$1" ];thenecho "need one parameter";exit 1;figrep "compile template:.* $1" test/* >hao.txtsed -e "/.*>/ s/\\(\d\\)*>/\\1/" hao.txt >hao1.txt#sed -e "/.*>/ s/\\(\d\\)*>/\\1/" hao.txt|sed -e "/,/ s/,/ /">hao2.txtsed -e "/,/ s/,/ /" hao1.txt >hao2.txt#sed -e "/2011-07-18 15/,/2011-07-18 16/p" hao1.txt >hao.txtawk 'BEGIN{max=0;sum=0;col=0;}{if($2>"23:59:00" && $2<"23:59:59"){if($7>max){max=$7};sum+=$7;col++}}END{print "count="col" max="max" sum="sum" avg="sum/col}' hao2.txt#awk 'BEGIN{max=0;sum=0;col=0;}{if($2>"23:59:00" && $2<"23:59:59"){print}}END{print "count="col" max="max" sum="sum" avg="sum/col}' hao2.txtexit 1;
#!/bin/shbegintime=00:00:00;endtime=23:59:59;argoption[1]="saveOrUpdateNews";argoption[2]="runplugin.*newscommon";argoption[3]="runplugin.*wireless";argoption[4]="postHandle";argoption[5]="update news";#argoption[1]="compile frag";#argoption[2]="compile template:.* EntityItem";#argoption[3]="compile template:.* Subject";#argoption[4]="compile template:.* News";#for strr in ${option
[*]}for strr in $(seq 5)do echo ${argoption[$strr]}; grep "${argoption[$strr]}" item/* >hao.txt sed -e "/.*>/ s/\\(\d\\)*>/\\1/" hao.txt >hao1.txt; sed -e "/,/ s/,/ /" hao1.txt >hao2.txt; awk -v btime="$begintime" -v etime="$endtime" 'BEGIN{max=0;min=1000;sum=0;col=0;}{if($2>=btime && $2<=etime){if($NF>max){max=$NF};if($NF<min){min=$NF};sum+=$NF ;col++}}END{print "count="col" max="max" sum="sum" avg="sum/col" min="min }' hao2.txt; rm hao*.txt;done
如果awk要传参数:
http://www.cnblogs.com/chengmo/archive/2010/10/03/1841753.html |
|