Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!rochester!ur-tut!sunybcs!rutgers!husc6!bu-cs!m2c!necntc!custom!boykin From: boykin@custom.UUCP (Joseph Boykin) Newsgroups: comp.unix.questions,comp.sources.wanted Subject: Re: Multiple Field Sorts in UNIX(tm) Message-ID: <758@custom.UUCP> Date: Wed, 22-Jul-87 10:53:06 EDT Article-I.D.: custom.758 Posted: Wed Jul 22 10:53:06 1987 Date-Received: Fri, 24-Jul-87 05:48:35 EDT References: <2459@whuts.UUCP> Organization: Custom Software Systems; Natick, MA Lines: 45 Summary: UNIX sort will do this Xref: mnetor comp.unix.questions:3290 comp.sources.wanted:1681 In article <2459@whuts.UUCP>, tes@whuts.UUCP (STERKEL) writes: > <*> > 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: ..... > 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. UNIX Sort (as well as our own PC/SORT) allows you to do exactly what you want. If you specify more than one sort key on the command line the file is sorted by the first key, if there is more than one line with the same information, the second key is used. There are a maximum of ten sort keys which may be specified. If all keys are used and they call compare equally, the entire line is used for a final check. I believe this is exactly what you are looking for. The format of doing this is as follows sort +pos1 [-pos2 [+pos3] [-pos4]]] file... +pos1 and -pos2 specify the first key with the field starting at position 1 and ending right before position 2. If the ending position is not specified, the end of the physical line is used. There are a bunch of options which help delimit what a field looks like, sorting order, etc. Check sort(1) for details. Joe Boykin Custom Software Systems ...necntc!custom!boykin -- Joe Boykin Custom Software Systems ...necntc!custom!boykin