I have a file that looks like this:
2017-07-30 A
2017-07-30 B
2017-07-30 B
2017-07-30 A
2017-07-30 A
2017-07-30 C
2017-07-31 A
2017-07-31 B
2017-07-31 C
2017-07-31 B
2017-07-31 C
Each line represent an event (A, B, or C) and the day it occured on.
I want to count the number events per type for each day.
This can be done with sort file | uniq -c, giving output like this:
3 2017-07-30 A
2 2017-07-30 B
1 2017-07-30 C
1 2017-07-31 A
2 2017-07-31 B
2 2017-07-31 C
However, I would like to have each event type as a column:
A B C
2017-07-30 3 2 1
2017-07-31 1 2 2
Is there a reasonably common command line tool that can do this? If necessary, it can be assumed that all event types (A, B, C) are known in advance, but it's better if it isn't necessary. Likewise it can be assumed that each event occurs at least once per day (meaning no zeros in the output), but here too it's better if it isn't necessary.