Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!seismo!uwvax!uwmacc!hobbes!root
From: root@hobbes.UUCP (John Plocher)
Newsgroups: comp.unix.questions,comp.sources.wanted
Subject: Multiple Field Sorts in UNIX(tm)
Message-ID: <154@hobbes.UUCP>
Date: Wed, 22-Jul-87 15:44:47 EDT
Article-I.D.: hobbes.154
Posted: Wed Jul 22 15:44:47 1987
Date-Received: Sat, 25-Jul-87 04:24:40 EDT
References: <2459@whuts.UUCP>
Reply-To: root@hobbes.UUCP (John Plocher)
Followup-To: comp.unix.questions
Distribution: na
Organization: U of Wisconsin - Madison  Spanish Department
Lines: 31
Xref: mnetor comp.unix.questions:3305 comp.sources.wanted:1689

+---- (STERKEL) writes the following in article <2459@whuts.UUCP> ----
|  I need a multiple field sort that maintains sub-field order.  Let
| 
|  An inefficient implementation of this has been:
|  cat file | sort on field3 | sort on field2 | sort on field1 > sorted
| 
| BUT, this only for sorts that are "bubble" and/or "shell". 
| Using Sort(1) "scrambles" the previous sorts on each pass,
| leaving me with no easy way to use sort(1) to do multiple
| field sorts.
+----

I use the following command to sort a "rolodex"(tm) type file into
post office acceptable order (by zip then by route then by name):
(The file is of the form "name","addr",...,"route","zip","phone";
thus the need for 8.1 and 5.1 to skip the quotes for sorting numeric
fields)

    sort -t, -y  +8.1 -8.7 -n  +5.1 -6.0 -d +0 -1 -o names.4 names.4

ie:               field 8       field 5      field 0
	           (zip)   (Rural Route/Box)  (name)

Sort(1) does the stable sorts for you.  This is using Sys5r2.

  - John

ps.   Yes I do backup the database before doing the in-place sort!

-- 
John Plocher uwvax!geowhiz!uwspan!plocher  plocher%uwspan.UUCP@uwvax.CS.WISC.EDU