awk文本工具按列計算和
文件內容:
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文本工具按列計算和