shell 多行求和,多行求平均值
来源:互联网 发布:最优化计算方法课后题 编辑:程序博客网 时间:2024/05/17 01:34
www.test.com 08 173816 14391 59673 71624 26898
www.test.com 08 12388 1203 3855 5094 2149
www.test.com 09 194304 19474 61445 76867 35068
www.test.com 09 89663 9640 27882 34700 16772
www.test.com 10 139121 14639 43812 53819 25821
www.test.com 10 214451 24306 65622 82117 40715
www.test.com 20 271252 30860 81361 103341 52574
www.test.com 20 4471 580 1355 1627 856
www.test.com 21 247062 30059 71196 93221 49215
www.test.com 21 121178 13874 35799 45516 24452
www.test.com 22 147896 17475 43636 54788 30010
www.test.com 22 253860 29097 75870 94667 50512
#合并多行的一列然后相加
file="20140730_result.log"
for domain in `cat domain.log`;do
cat $file | grep $domain | awk '{ sum[$2] += $3; } END { for (i in sum) { print i," count_total "sum[i], "\t"; } }' > $domain"_count_total.log"
cat $file | grep $domain | awk '{ sum[$2] += $4; } END { for (i in sum) { print i," count_hit "sum[i], "\t"; } }' > $domain"_count_hit.log"
cat $file | grep $domain | awk '{ sum[$2] += $5; } END { for (i in sum) { print i," count_cache_first_write "sum[i], "\t"; } }' > $domain"_count_cache_first_write.log"
cat $file | grep $domain | awk '{ sum[$2] += $6; } END { for (i in sum) { print i," count_cache_expired_write "sum[i], "\t"; } }' > $domain"_count_cache_expired_write.log"
cat $file | grep $domain | awk '{ sum[$2] += $7; } END { for (i in sum) { print i," count_real_back "sum[i], "\t"; } }' > $domain"_count_real_back.log"
cat $domain_count* | awk '{if(!a[$1]){a[$1]=$1" "$2" "$3;}else{a[$1]=a[$1]" "$2" "$3}}END{for(i in a){print a[i]}}' > $domain"_tmp.log"
cat $domain"_tmp.log" | awk '{print $1" "$2" "$3" "100/($11/$3)" "$4" "$5" "100/($11/$5)" "$6" "$7" "100/($11/$7)" "$8" "$9" "100/($11/$9)" "$10" "$11}' > "result_"$domain".log"
done
cat 20140730_result.log| grep www.test.com | awk '{ sum[$2] += $3; } END { for (i in sum) { print i," count_total "sum[i], "\t"; } }' > www.test.com_count_total.log
cat 20140730_result.log| grep www.test.com | awk '{ sum[$2] += $4; } END { for (i in sum) { print i," count_hit "sum[i], "\t"; } }' > www.test.com_count_hit.log
cat 20140730_result.log| grep www.test.com | awk '{ sum[$2] += $5; } END { for (i in sum) { print i," count_cache_first_write "sum[i], "\t"; } }' > www.test.com_count_cache_first_write.log
cat 20140730_result.log| grep www.test.com | awk '{ sum[$2] += $6; } END { for (i in sum) { print i," count_cache_expired_write "sum[i], "\t"; } }' > www.test.com_count_cache_expired_write.log
cat 20140730_result.log| grep www.test.com | awk '{ sum[$2] += $7; } END { for (i in sum) { print i," count_real_back "sum[i], "\t"; } }' > www.test.com_count_real_back.log
cat www.test.com_count* | awk '{if(!a[$1]){a[$1]=$1" "$2" "$3;}else{a[$1]=a[$1]" "$2" "$3}}END{for(i in a){print a[i]}}' > result_tmp.log
cat result_tmp.log | awk '{print $1" "$2" "$3" "100/($11/$3)" "$4" "$5" "100/($11/$5)" "$6" "$7" "100/($11/$7)" "$8" "$9" "100/($11/$9)" "$10" "$11}' > result_www.che.168.com.log
#获取某个时间点的某个域名的响应时间的平均值(多行的平均数)
state="HIT"
for domain in `cat domain/domain.log`;do
cat access.log | sed -n '/2014-07-31 13:20:00/,/2014-07-31 14:20:00/p' | awk -F '\t' '{if($5!=$state && $8=$domain) print $6 }' | awk 'BEGIN { a=0 };{a=a+$0}; END{print a/NR}'
done
www.test.com 08 12388 1203 3855 5094 2149
www.test.com 09 194304 19474 61445 76867 35068
www.test.com 09 89663 9640 27882 34700 16772
www.test.com 10 139121 14639 43812 53819 25821
www.test.com 10 214451 24306 65622 82117 40715
www.test.com 20 271252 30860 81361 103341 52574
www.test.com 20 4471 580 1355 1627 856
www.test.com 21 247062 30059 71196 93221 49215
www.test.com 21 121178 13874 35799 45516 24452
www.test.com 22 147896 17475 43636 54788 30010
www.test.com 22 253860 29097 75870 94667 50512
#合并多行的一列然后相加
file="20140730_result.log"
for domain in `cat domain.log`;do
cat $file | grep $domain | awk '{ sum[$2] += $3; } END { for (i in sum) { print i," count_total "sum[i], "\t"; } }' > $domain"_count_total.log"
cat $file | grep $domain | awk '{ sum[$2] += $4; } END { for (i in sum) { print i," count_hit "sum[i], "\t"; } }' > $domain"_count_hit.log"
cat $file | grep $domain | awk '{ sum[$2] += $5; } END { for (i in sum) { print i," count_cache_first_write "sum[i], "\t"; } }' > $domain"_count_cache_first_write.log"
cat $file | grep $domain | awk '{ sum[$2] += $6; } END { for (i in sum) { print i," count_cache_expired_write "sum[i], "\t"; } }' > $domain"_count_cache_expired_write.log"
cat $file | grep $domain | awk '{ sum[$2] += $7; } END { for (i in sum) { print i," count_real_back "sum[i], "\t"; } }' > $domain"_count_real_back.log"
cat $domain_count* | awk '{if(!a[$1]){a[$1]=$1" "$2" "$3;}else{a[$1]=a[$1]" "$2" "$3}}END{for(i in a){print a[i]}}' > $domain"_tmp.log"
cat $domain"_tmp.log" | awk '{print $1" "$2" "$3" "100/($11/$3)" "$4" "$5" "100/($11/$5)" "$6" "$7" "100/($11/$7)" "$8" "$9" "100/($11/$9)" "$10" "$11}' > "result_"$domain".log"
done
cat 20140730_result.log| grep www.test.com | awk '{ sum[$2] += $3; } END { for (i in sum) { print i," count_total "sum[i], "\t"; } }' > www.test.com_count_total.log
cat 20140730_result.log| grep www.test.com | awk '{ sum[$2] += $4; } END { for (i in sum) { print i," count_hit "sum[i], "\t"; } }' > www.test.com_count_hit.log
cat 20140730_result.log| grep www.test.com | awk '{ sum[$2] += $5; } END { for (i in sum) { print i," count_cache_first_write "sum[i], "\t"; } }' > www.test.com_count_cache_first_write.log
cat 20140730_result.log| grep www.test.com | awk '{ sum[$2] += $6; } END { for (i in sum) { print i," count_cache_expired_write "sum[i], "\t"; } }' > www.test.com_count_cache_expired_write.log
cat 20140730_result.log| grep www.test.com | awk '{ sum[$2] += $7; } END { for (i in sum) { print i," count_real_back "sum[i], "\t"; } }' > www.test.com_count_real_back.log
cat www.test.com_count* | awk '{if(!a[$1]){a[$1]=$1" "$2" "$3;}else{a[$1]=a[$1]" "$2" "$3}}END{for(i in a){print a[i]}}' > result_tmp.log
cat result_tmp.log | awk '{print $1" "$2" "$3" "100/($11/$3)" "$4" "$5" "100/($11/$5)" "$6" "$7" "100/($11/$7)" "$8" "$9" "100/($11/$9)" "$10" "$11}' > result_www.che.168.com.log
#获取某个时间点的某个域名的响应时间的平均值(多行的平均数)
state="HIT"
for domain in `cat domain/domain.log`;do
cat access.log | sed -n '/2014-07-31 13:20:00/,/2014-07-31 14:20:00/p' | awk -F '\t' '{if($5!=$state && $8=$domain) print $6 }' | awk 'BEGIN { a=0 };{a=a+$0}; END{print a/NR}'
done
0 0
- shell 多行求和,多行求平均值
- Java 求和及平均值
- awk 求和,求平均值
- shell脚本编程实例--进度条,求和&平均值,斐波那契,改变字符串大小顺序
- iOS数组求和、求平均值
- awk 求和、最大、最小、平均值
- shell awk 多列求和
- GridView加入自动求和求平均值小计
- GridView加入自动求和求平均值小计
- GridView加入自动求和求平均值小计
- GridView加入自动求和求平均值小计
- GridView加入自动求和求平均值小计?
- GridView自动求和、求平均值小计
- valueForKeyPath计算求和、平均值、最大、最小
- awk求和、平均值、最大小值
- Shell-计算多行数值求和
- shell应用:数据求和
- shell 求和的方法
- springMVC静态资源路径问题解决办法
- Qt for Android 项目中,创建的工程路径中不可以有空格
- Java基础笔记之NIO
- 正则表达式30分钟入门教程
- aac文件解析
- shell 多行求和,多行求平均值
- iOS单例模式和单例的写法
- 研大考研:考研政治复习范围及考试内容
- java中多种方式读文件
- 记录集
- poj-3624-Charm Bracelet
- Xperia Z1参数及白皮书
- 华为12年编程大赛:将字符串中的数字进行排序
- java下载远程服务器中以中文命名的文件