views:

401

answers:

2

I have a command (cmd1) that greps through a log file to filter out a set of numbers. the numbers are in random order, so i use sort -gr to get a reverse sorted list of numbers. there may be duplicates within this sorted list. I need to find the count for each unique number in that list.

For e.g. if the output of cmd1 is

100 100 100 99 99 26 25 24 24

I need another command that i can pipe the above output to, so that, i get :

100 3 99 2 26 1 25 1 24 2

A: 

if order is not important

# echo "100 100 100 99 99 26 25 24 24" | awk '{for(i=1;i<=NF;i++)a[$i]++}END{for(o in a) printf "%s %s ",o,a[o]}'
26 1 100 3 99 2 24 2 25 1
ghostdog74
+4  A: 

how about;

$ echo "100 100 100 99 99 26 25 24 24" | tr " " "\n" | sort | uniq -c | sort -k2nr | awk '{printf("%s %s ",$2,$1)}END{print}'
100 3 99 2 26 1 25 1 24 2
Stephen Paul Lesniewski