awk文本工具按列计算和
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了awk文本工具按列计算和相关的知识,希望对你有一定的参考价值。
需求:对文件中第一列相同的关键字的行进行sum,文件内容如下
文件内容:
Insert 170
Total_Data_Bytes 3886
Delete 0
Insert 170
Total_Data_Bytes 3886
Delete 0
Insert 0
Insert 170
Total_Data_Bytes 3886
Delete 0
Insert 0
FieldComp 0
Insert 170
Total_Data_Bytes 3886
Delete 0
Insert 0
FieldComp 0
GGSPKUpdate 0
Insert 170
Total_Data_Bytes 3886
Delete 0
Insert 0
FieldComp 0
GGSPKUpdate 0
GGSPurgedata 0
Insert 170
Total_Data_Bytes 3886
Delete 0
Insert 0
FieldComp 0
GGSPKUpdate 0
GGSPurgedata 0
Total_Data_Bytes 0
处理后效果(分别统计Delete,FieldComp,GGSPKUpdate,GGSPurgedata,Insert,Total_Data_Bytes相同的行进行求和)
Delete: 0
FieldComp: 0
GGSPKUpdate: 0
GGSPurgedata: 0
Insert: 1020
Total_Data_Bytes: 23316
shell代码:
var_text=`cat /u01/app/oracle/ogg/ogg_lastdata/49/GRMCDB.CBS_T2.txt|awk '{print $1}'|sort|uniq > /home/oracle/oggscript/vartextlist`
while read line
do
var1=$line
case $var1 in
"Delete")
grep "Delete" /u01/app/oracle/ogg/ogg_lastdata/49/GRMCDB.CBS_T2.txt|awk 'BEGIN {count=0} {count+=$2;} END {print "Delete:",count}';;
"FieldComp")
grep "FieldComp" /u01/app/oracle/ogg/ogg_lastdata/49/GRMCDB.CBS_T2.txt|awk 'BEGIN {count=0} {count+=$2;} END {print "FieldComp:",count}';;
"GGSPKUpdate")
grep "GGSPKUpdate" /u01/app/oracle/ogg/ogg_lastdata/49/GRMCDB.CBS_T2.txt|awk 'BEGIN {count=0} {count+=$2;} END {print "GGSPKUpdate:",count}';;
"GGSPurgedata")
grep "GGSPurgedata" /u01/app/oracle/ogg/ogg_lastdata/49/GRMCDB.CBS_T2.txt|awk 'BEGIN {count=0} {count+=$2;} END {print "GGSPurgedata:",count}';;
"Insert")
grep "Insert" /u01/app/oracle/ogg/ogg_lastdata/49/GRMCDB.CBS_T2.txt|awk 'BEGIN {count=0} {count+=$2;} END {print "Insert:",count}' ;;
"Total_Data_Bytes")
grep "Total_Data_Bytes" /u01/app/oracle/ogg/ogg_lastdata/49/GRMCDB.CBS_T2.txt|awk 'BEGIN {count=0} {count+=$2;} END {print "Total_Data_Bytes:",count}';;
esac
done < /home/oracle/oggscript/vartextlist
以上是关于awk文本工具按列计算和的主要内容,如果未能解决你的问题,请参考以下文章