We have this file:
1 2 1 3 1 2 3 3 52 1 52 300
and 1000 more.
I want to count the number of times each value occurs in the first column.
1 3 3 1 52 2
This means we saw
1 three times.
How can I do that, in Perl, AWK or Bash?
If the input is sorted, you can use uniq:
If not, sort it first:
The output is swapped compared to your requirement, you can use
There's also the awk idiom, which does not require sorted input:
As the output here comes from a hash it will not be ordered, pass to
If you're using GNU awk, you can do the sorting from within awk:
In the last two cases the output is: