On 30/05/2022 18:43, Karl Berry wrote:
How about supporting negative POS values for -k to count from the last
field? Useful when there are a varying number of fields. Crazy?

E.g., two-line file
   x/y/z
   a/b
desired to sort on last field via:
   sort -t/ -k -1,-1

Clearly there are ways to achieve the goal, e.g., extract and duplicate
the last field to the beginning, or use Perl/awk/whatever to do the
sorting, but ... just thought I'd throw it out there ... -k

Yes there is some merit in that, and it was discussed a long time ago at:
https://lists.gnu.org/archive/html/bug-coreutils/2006-09/msg00106.html

In general we prefer users use the more general "DSU" pattern
to modify the data (as you mentioned), rather than complicating
the already complicated field selection syntax. We give an example
in texinfo to sort by line length, as a hint to how to use this style:

  awk '{print length, $0}' /etc/passwd | sort -n | cut -f2- -d' '

cheers,
Pádraig

Reply via email to