Steve Litt wrote:

fmt -1 < tsjustfacts.txt | sed -e "s/^[[:space:][:punct:]]*//" | sed -e "s/[[:space:][:punct:]]*$//" | tr [:upper:] [:lower:] | sort | uniq -c | sort -rn

The one thing this doesn't do is, upon final sort, sort by count descending but name ascending. Can you think of a way to do that with standard Linux commands?

Do you mean you want a sort key composed of the count, sorted numerically and descending, and the name, sorted lexically and ascending? So that words with the same count will be grouped together in the output and, within that group, sorted lexically?

Change the final sort to specify a multipart key:

   sort -k 1nr -k 2

That says "sort by a key composed of the first field, taken as numeric, in reverse order; and the second field, using the default options (lexicographic and ascending).

This syntax is standard for sort(1) as of SUSv3, by the way - it's not specific to Linux.

--
Michael Wojcik

Reply via email to