awk text tool calculate sum by column

Requirement: Sum the lines with the same keyword in the first column of the file, the content of the file is as follows

document content:

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

After processing effect (respectively count Delete, FieldComp, GGSPKUpdate, GGSPurgedata, Insert, Total_Data_Bytes same lines for summation)

Delete: 0

FieldComp: 0

GGSPKUpdate: 0

GGSPurgedata: 0

Insert: 1020

Total_Data_Bytes: 23316

shell code:

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


                                     


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324643604&siteId=291194637