[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: -k -1 for last field?
From: |
Pádraig Brady |
Subject: |
Re: -k -1 for last field? |
Date: |
Mon, 30 May 2022 20:49:29 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:98.0) Gecko/20100101 Thunderbird/98.0 |
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