Script / sort question; sort on last field of a line?
Tim Writer
tim-s/rLXaiAEBtBDgjK7y7TUQ at public.gmane.org
Thu May 4 18:26:38 UTC 2006
Peter <plp-ysDPMY98cNQDDBjDh4tngg at public.gmane.org> writes:
> On Thu, 4 May 2006, Walter Dnes wrote:
>
> > How do I sort on the last (or 2nd last or whatever) field of a line?
> >
> > One awkward possibility involves rewriting the lines backwards,
> > sorting on what is now the first field, and rewriting the lines
> > backwards a second time. I'm not aware of a utility to do write lines
> > backwards. I am *NOT* thinking of "tac" which writes the lines
> > unaltered but reverses their order. I want to write *EACH INDIVIDUAL
> > LINE* backwards. The following script does what I want...
>
> Rewriting backwards and sorting will cause trouble because of padding
> (reversed abcz is before reversed abca)
>
>
> sort -rk ... should do it
This is by far the easiest solution posted, although I'm not sure why you
would need "-r". That reverses the sort order (i.e. to reverse alphabetic)
which wasn't in the problem description.
Just to clarify Peter's answer. If you have N fields in a line, use:
sort -k N
For details see:
info coreutils sort
--
tim writer <tim-s/rLXaiAEBtBDgjK7y7TUQ at public.gmane.org> starnix inc.
647.722.5301 toronto, ontario, canada
http://www.starnix.com professional linux services & products
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list