Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!math.lsa.umich.edu!emv From: emv@math.lsa.umich.edu (Edward Vielmetti) Newsgroups: comp.unix.questions Subject: Re: Shell Programming Question - sort Message-ID: Date: 3 Mar 90 09:02:29 GMT References: <751@ncs.dnd.ca> Sender: news@math.lsa.umich.edu Organization: University of Michigan Math Dept., Ann Arbor MI. Lines: 25 In-reply-to: marwood@ncs.dnd.ca's message of 3 Mar 90 04:39:07 GMT In article <751@ncs.dnd.ca> marwood@ncs.dnd.ca (Gordon Marwood) writes: 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 ? Here's how I'd do it in perl: perl -e '@all=<>;sub l {substr($a,2,-2)-substr($b,2,-2);}; print sort l @all;' If I had to do it without perl, I'd use awk to copy the last two characters on the line to the beginning, sort on those, and then sed them out. Glad I don't have to do that anymore. Just ano...no, you don't want to hear that, --Ed Edward Vielmetti, U of Michigan math dept.