awk 'END { for (k in r) t[sprintf("%10d", r[k])] = k n = asorti(t, _) while (++i <= n) print t[_[i]] } { r[$0] = NR }' filename