What you appear to want is called a cross tabulation or contingency table .
While it's certainly possible to implement a solution using generic tools such as awk
, perl
, or python
, the easiest approach IMHO would be to install GNU datamash - you can then straightforwardly do
datamash --sort --whitespace --filler=0 crosstab 2,1 sum 3 < file
If there's only a single entry per pair (as appears to be the case in your example), then you can use unique
in place of sum
.
You can also do cross-tabulation in many spreadsheet applications - where it's often called pivot tables.