On Mon, Aug 19, 2002 at 05:31:14PM -0400, Kevin D. Clark <[EMAIL PROTECTED]> wrote: > You have a list of stuff that you want sorted. The problem is is that > you want your stuff sorted according to a field contained in the input > (the last field). Further complicating matters is the fact that this > field is located at a non-constant place in the input field.
I was thinking that `sort -t / -k -1` would be really cool here, but sort can't sense of a negative column index. I wonder is the FSF would accept such a patch to GNU sort? > The solution: take the input, generate a list from each line, each > element in the list consists of a tuple consisting of the original > line plus the comparison key. Sort the tuple-list using the > comparison key, and then after the sort is done, strip off all of the > comparison keys, returning the original list ({sans} tuples), sorted. > > This is actually a well-known technique in Perl, called the > Schwartzian Transform. Look it up on the web -- there are plenty of > good descriptions of it. That is basically what my example did, but continuing to use sed and sort instead of perl (for no particular reason -- I could come up with rationales but they may not be applicable). My suggestion took the filename, prepended it so sort could get at it, sorted the data by the first column only, and then removed that column. Since I don't see my post for some reason, I'll repeat it here: sed -e 's;\(\(.*\)/\)*\(.*\);\3/\1\3;' | sort -fdt/k1 | sed -e 's;[^/]*/\(.*\);\1;' Since this is mildly different, and I've never heard of the Schwartzian Transform, I'm going to propose calling this Bell's Method. :-) -- Bob Bell <[EMAIL PROTECTED]> ------------------------------------------------------------------------- "The greatest wage gains between 1997 and last year (1998) were reported by people working with Linux, a free operating system. Their knowledge of this increasingly popular system puts them in high demand for Internet projects..." -- http://detnews.com/1999/technology/9901/08/01080223.htm _______________________________________________ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss