jacob@sri-unix (08/24/82)
What I would like to know is if it is possible to sort a file by ONLY the first field? No mather how I try, it always sorts by all fields. I would think that by typing: sort +0.0 -1.0 foo it should work, but it doesn't. Someone told me that the manual information on sort (specifically on the +pos and -pos) is incorrect, is that true? Our UNIX version is 4.1BSD. Thank you. Jacob Bulaevsky megatest
johnl (08/30/82)
You can't tell Unix sort to sort only on the first field. The manual says that lines that otherwise compare equal are sorted on the whole line. If you want a stable sort (i.e., equal lines stay in their original order) you have to be explicit and number the lines beforehand, sort with +0n ..., and unnumber them. Gross but true. The sorting algorithm used is not easily persuaded to sort stably and if sort had a "stable" flag it would have to do the numbering itself. Under 3.0, the following command line will do the trick: pr -n -t | sort +0n $* | cut -c7- If you are missing "cut" and "pr -n", you can use sed: sed = | sed 'N s/\n/ /' | sort +0n $* | sed '[0123456789]* ' John Levine, decvax!cca!ima!johnl, harpo!esquire!ima!johnl (uucp) Levine@YALE (Arpa), 617-491-5450 (desperation)
gwyn@Brl@sri-unix (09/07/82)
From: Doug Gwyn <gwyn@Brl> Date: 4 Sep 82 23:09:07-EDT (Sat) One could always specify multiple sort keys; the later keys would only be used when earlier keys tied, so there would be little additional overhead. The entire-line ordering is of course only invoked when all keys match.