sed&& awk

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/sh
echo $1
if [ -z "$1" ];then
echo "need one parameter";
exit 1;
fi
grep "compile template:.* $1" test/* >hao.txt
sed -e "/.*>/ s/\\(\d\\)*>/\\1/" hao.txt >hao1.txt
#sed -e "/2011-07-18 15/,/2011-07-18 16/p" hao1.txt >hao.txt
awk '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.txt
exit 1;

每天23:59:00到23:59:59的触发量
#!/bin/sh
echo $1
if [ -z "$1" ];then
echo "need one parameter";
exit 1;
fi
grep "compile template:.* $1" test/* >hao.txt
sed -e "/.*>/ s/\\(\d\\)*>/\\1/" hao.txt >hao1.txt
#sed -e "/.*>/ s/\\(\d\\)*>/\\1/" hao.txt|sed -e "/,/ s/,/ /">hao2.txt
sed -e "/,/ s/,/ /" hao1.txt >hao2.txt
#sed -e "/2011-07-18 15/,/2011-07-18 16/p" hao1.txt >hao.txt
awk '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.txt
exit 1;

#!/bin/sh
begintime=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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值