Sorting is taking a collection of things and putting them into some specific order. For example, sorting people by age, shoes by size, strings by length, planets by mass, numbers by value.
Frequently Asked Questions about sorting
For sorting the lines of a file being read from standard input, and writing the result out to standard output, one can use the following one-liner:
puts [join [lsort [split [read stdin] \n]] \n]
Or in English: read in all the data to sort, split it into the list of units to be sorted, sort that list, join the sorted list back up in the external format, and write it out.
AMG: At least on Unix, most files end with a newline. The above code interprets newlines as line separators, not line terminators, so when the last character of the file is a newline, it thinks a zero-length line follows. [regsub {\n$} [read stdin] ""] can be used to get the contents of the file sans a trailing newline.
AK - 2010-03-05 13:15:20
IMHO string trimright read stdin \n looks nicer and easier to understand. Internally simpler too I would guess (No regexp engine).