I have a file with four columns separated by ";" which looks exemplary like this:
Articles;Qty;Sales;Customers
ArticleA;2;6;Customer1
ArticleA;3;9;Customer2
ArticleA;5;15;Customer1
ArticleA;4;12;Customer1
ArticleB;1;2;Customer2
ArticleB;2;4;Customer1
ArticleC;3;3;Customer2
I would like make a sum per article for columns 2 and 3, I can do that with the following command:
awk -F ';' 'NR>1 {a[$1]+=$2; b[$1]+=$3} END {for (i in a) print i, a[i], b[i]}' File
But now I would also like to know how many different customers have bought this article. Unfortunately, I can't do that. Can someone tell me how my awk command should be so that I get the following result:
Articles;Qty;Sales;Count of different customers
ArticleA;14;42;2
ArticleB;3;6;2
ArticleC;3;3;1