Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!hplabs!hpda!hpcuhc!hpsemc!gph From: gph@hpsemc.HP.COM (Paul Houtz) Newsgroups: comp.unix.questions Subject: Re: sort question Message-ID: <810050@hpsemc.HP.COM> Date: 8 May 89 19:01:27 GMT References: <199448@hrc.UUCP> Organization: HP Technology Access Center, Cupertino, CA Lines: 59 guy@auspex.auspex.com (Guy Harris) writes: >Try: sort +10 -11 +2 -3 filename > >This tells sort to sort first on a field starting in col. 10 and ending just >before col. 11, No, it doesn't, at least not if you're talking about the standard UNIX versions of "sort". It tells "sort" to sort first on the 10th *field* (that is, the 11th field on the line - after all, it's written in C :-)). Fields are normally separated by white space; with the "-t" flag, they're separated by tab columns. ---------- Right. There is no way to do a true column sort using this utility as you can on IBM or MPE systems and here is why: Sort requires a FIELD DELIMITER character. That means that there is SOME character that will never be sorted. If you need to sort data from a foreign file about which you have little information except column numbers to sort on, you are (as far as I know) out of luck with 'sort'. If, however, you do know of some character which will NEVER appear as data in a file, then you can do a column sort. For instance, say you know that the charactyer '^' never appears in your data file. Then you can simply say: sort -t^ -0.0 + 0.3 This command assumes that there is only ONE field in the file, and that is the entire record. It then sorts the 0+0th column of the 0+0th field thru the 0+4th column of the 0+0th field, actually accomplishing a sort of column 1 thru 4. Here is the worst one I have seen on Unix. I converted this myself from a sort done on an IBM System/34. This is a good example of a COMMON type of sort done in the commercial world which you never see on Unix: sort -dt'\012' +0.6 -0.8 +0.13 -0.15 +0.15r -0.17r +0.8 -0.13 DISK-SUMARY >SUM1 This guy sorts the summary file using the newline character as a field delimiter (i.e., no fields), and you can tell what column ranges are being sorted by subtracting 1 from the 'x' field of the 0.x parms. It sorts the 5 thru 7 columns in ascending order, the 12 thru 14 columns in ascending order, the 14 thru 16 columns in DESCENDING order, (the "r" after the column) then the 7 thru 12 columns in ascending order. If anyone ever tries to tell you that UNIX is user friendly, you can now barf on them. Paul Houtz HP Technology Access Center 10670 N. Tantau Avenue Cupertino, Ca 95014 (408) 725-3864 hplabs!hpda!hpsemc!gph gph%hpsemc@hplabs.HP.COM