If I have a text file with the following conent
red apple
green apple
green apple
orange
orange
orange
Is there a Linux command or script that I can use to get the following result?
1 red apple
2 green apple
3 orange
If I have a text file with the following conent
red apple
green apple
green apple
orange
orange
orange
Is there a Linux command or script that I can use to get the following result?
1 red apple
2 green apple
3 orange
Send it through
sort
(to put adjacent items together) thenuniq -c
to give counts, i.e.:and to get that list in sorted order (by frequency) you can
uniq -c file
and in case the file is not sorted already:
sort file | uniq -c
Try this
Almost the same as borribles' but if you add the
d
param touniq
it only shows duplicates.To just get a count:
To get a sorted count:
EDIT
Aha, this was NOT along word boundaries, my bad. Here's the command to use for full lines: