i.e from this list
papajack
Toalla
ourma
ourma
ChuckRobbins
ChuckRobbins
patrick41
patrick41
Velocity
Velocity
Velocity
Velocity
Velocity
maximosz
maximosz
maximosz
Toalla
get:
5 Velocity
3 maximosz
2 patrick41
2 ourma
2 Toalla
2 ChuckRobbins
1 papajack
The original list are not sorted - Toalla for instance if at the top and
bottom, but of course sorting them would be trivual.
Any thoughts? Is this something a perl guru can do, or do I need to
write some C code?
The number of usernames in the list is around 4000, so efficiency is not
going to be a major concern. Any have decent solution should be able to
work on 4000 without much difficulty.
try this:
cat << EOF | \
awk ' { arr[$1]++ }
END { for (Name in arr)
{
printf "%d\t%s\n", arr[Name], Name;
}}' | sort -rn
papajack
Toalla
ourma
ourma
ChuckRobbins
ChuckRobbins
patrick41
patrick41
Velocity
Velocity
Velocity
Velocity
Velocity
maximosz
maximosz
maximosz
Toalla
EOF
sort | uniq -c | sort -rn
--
Stéphane
sort file | uniq -c | sort -rn
Ed.
perl -lne'++$x{$_}}{print"$x{$_}\t$_"for sort{$x{$b}<=>$x{$a}}keys%x'
yourfile
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
Thank you everyone who replied. Clearly
sort filename | uniq -c | sort -rn
is much easier than some of the other solutions.
Dave