2

I have a one column file composed by only integer as

1
1
4
3
3
2

I want to count how many time a number appear in the file. The output file should be:

1 2
2 1
3 2
4 1

Thanks

4

2 回答 2

4

试试这一行:

awk '{a[$0]++}END{for(x in a)print x,a[x]}' file
于 2013-03-24T11:29:17.503 回答
1
awk '{tot[$0]++} END{for (n in tot) {print n,tot[n]}} ' numbers
于 2013-03-24T11:30:07.277 回答