I have a data file which contains 15000 lines, but only 400 unique values. I am looking for a way to identify the number of unique values and then the number of occurrences of those values in the file. I came up with the following but it is very very slow. Any thoughts?
for value in `cat mylist.txt | uniq`
do
counter=`grep $value mylist.txt |wc -l`
echo $value $counter
done

cat file | uniq; like most Unix text utilities, uniq can take a filename as an argument for input – itsbruce Oct 9 '12 at 16:07sort file | uniqis better. – terdon Oct 9 '12 at 16:43