question on awk (bash)to sum values par item . Inputfile looks like :
item value
----------------
item1 8
item1 1
item1 5
item2 2
item2 8
item3 4
item3 7
item3 7
Timely Total xxx
item1 5
item1 4
item1 3
item2 4
item2 1
Timely Total 17
my question : To have sum par item : i have code
awk '{a[$1]+=$2}END{for(i in a) print i,"has" ,a[i] " entries" }'
thats fine . but they sum the whole file for all item1's in all Timelytotals
I need a sum of item1 in Timely total1 , sum of item2 in Timely total1 , sum of item3 in Timely total1.
Sum of item1 in Timelytotals2 , sum of item2 in Timelytotals2 , sum of item3 in Timelytotals2 Similar for more Timely totals .
Thank you luc
Aucun commentaire:
Enregistrer un commentaire