Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!cica!tut.cis.ohio-state.edu!snorkelwacker!mit-eddie!uw-beaver!zephyr.ens.tek.com!tektronix!reed!justin From: justin@reed.bitnet (the specific heat) Newsgroups: comp.unix.questions Subject: Re: Shell Programming Question - sort Message-ID: <14387@reed.UUCP> Date: 9 Mar 90 23:02:35 GMT References: <751@ncs.dnd.ca> <3190@hcx1.SSD.CSD.HARRIS.COM> Sender: news@reed.UUCP Lines: 38 Gordon Marwood says: >I am trying to sort (using "sort" in Ultrix) based on the last two >characters in a line (which are numeric). There are a variable number >of characters in a line, and these last two characters are preceded by a >space, there are also a variable number of spaces in a line, so the >number of fields will be variable if space is used as the field >separator. None of my available texts gives me a clue as to whether a >sort can be done based on the last field in a line, regardless of the >number of fields in the line. Is there any "sort" option that can >do this ? The way to do this using standard unix tools which comes most quickly to my mind is: $ awk '{ print $NF " " $0}' filename | sort -n | sed 's/[^ ]* //' . The first command prepends the last field to the line, and the last undoes that. The output will be on stdout, so you'll have to deal with that. Brad Appleton suggests using reverse(1STAT) which has, on our machine, a -f (reverse by fields) option. So you'd do $ reverse -f