From: utzoo!decvax!cca!ima!johnl
Newsgroups: net.unix-wizards
Title: Re: Sort Problem
Article-I.D.: ima.208
Posted: Mon Aug 30 12:13:04 1982
Received: Wed Sep  8 03:29:05 1982
References: megatest.134

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)