I cannot find awk solution for this simple task. I can easily sum the column ($ 3) based on a single matching field ($ 1) with:
awk -F, '{array[$1]+=$3} END { for (i in array) {print i"," array[i]}}' datas.csv
Now, how can I do this based on two fields? Say $ 1 and $ 2? Here is an example of data:
P1,gram,10 P1,tree,12 P1,gram,34 P2,gram,23 ...
I just need to sum column 3 if the first and second fields match.
Thanx for any help!
source share