@claudiom Nice. I have written stuff using Awk to do frequency counts but 'uniq -c' is so elegant.
Also, in Bash the newline for the first 'tr' can be written as $'\n' rather than the two line thing.
Not sure about the sed bit. I'd have used 'sed -n 1p' but maybe I'm wrong ;-)