Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!rutgers!sri-spam!ames!ptsfa!ihnp4!twitch!homxb!whuts!tes From: tes@whuts.UUCP (STERKEL) Newsgroups: comp.unix.questions,comp.sources.wanted Subject: Multiple Field Sorts in UNIX(tm) Message-ID: <2459@whuts.UUCP> Date: Tue, 21-Jul-87 10:09:45 EDT Article-I.D.: whuts.2459 Posted: Tue Jul 21 10:09:45 1987 Date-Received: Fri, 24-Jul-87 01:16:58 EDT Organization: AT&T Bell Laboratories Lines: 49 Xref: mnetor comp.unix.questions:3280 comp.sources.wanted:1674 <*> I am not certain if this is a neophyte question (comp.unix.question) or a request for software (comp.sources.wanted). If you respond with sources, please, please, please make certain that it is fully compatible with vanilla SysV. Thanks. <*> Now for the problem: I need a multiple field sort that maintains sub-field order. Let me draw a picture: File contents field 0 field 1 field x field 2 field y field 3 field z ------- ------- ------- ------- ------- ------- ------ ... aaa ... ... ... ... ... ... bbb ... ... ... ... ... ... bba ... aaa ... ... ... ... bba ... aab ... axa ... ... bba ... aab ... aya ... ... bba ... aac ... xxx ... ... bba ... aac ... xxx ... ... ccc ... ... ... ... ... ... dcc ... ... ... ... ... ... ecc ... ... ... ... ... ... fcc ... aaa ... ... ... ... fcc ... bbb ... ... ... ... fcc ... ccc ... aaa ... ... fcc ... ccc ... aab ... etc note: "..." denotes that field contents do not affect sort order. In narrative form: Multiple Field Sorts sort on the first field, then on the second field if the first field has two or more records with identical contents, then on the third field if the second field has two or more records with identical contents, then on the fourth...etc. 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. Any hints? -- Terry Sterkel {clyde|harvard|cbosgd|allegra|ulysses|ihnp4}!whuts!tes [opinions are obviously only my own]