I'm trying to use GNU sort on a directory/file listing, eg (subset of much longer listing):
exams2008/Zoology/Summer/ZY4019Sum08.pdf
exams2009/Zoology/Summer/ZY4019.pdf
exams2010/Zoology/Summer/ZY4019Sum2010.pdf
exams2011/Zoology/Summer/ZY4019Sum2011.pdf
exams2012/Zoology/Autumn/ZY4019Aut2012.pdf
exams2012/Zoology/Summer/ZY4019Sum2012.pdf
exams2013/Zoology/Autumn/ZY4019Aut2013.pdf
exams2013/Zoology/Summer/ZY4019Sum2013.pdf
exams2014/Zoology/Summer/ZY4019Sum2014.pdf
I am already sorting this successfully on the filename (4th field) followed by the season (3rd field), eg
$ sort -t/ -k4 -k3,3
exams2012/Zoology/Autumn/ZY4019Aut2012.pdf
exams2013/Zoology/Autumn/ZY4019Aut2013.pdf
exams2009/Zoology/Summer/ZY4019.pdf
exams2008/Zoology/Summer/ZY4019Sum08.pdf
exams2010/Zoology/Summer/ZY4019Sum2010.pdf
exams2011/Zoology/Summer/ZY4019Sum2011.pdf
exams2012/Zoology/Summer/ZY4019Sum2012.pdf
exams2013/Zoology/Summer/ZY4019Sum2013.pdf
exams2014/Zoology/Summer/ZY4019Sum2014.pdf
But for each block like this, I need them in descending year order as the third sort criterion, using the four digits from position 6 thru 9 of the first field. If I use:
sort -t/ -k4 -k3,3 -k1.6nr,1.9
which looks as if it ought to work, but it does not sort that third criterion in reverse numeric order:
exams2012/Zoology/Autumn/ZY4019Aut2012.pdf
exams2013/Zoology/Autumn/ZY4019Aut2013.pdf
exams2009/Zoology/Summer/ZY4019.pdf
exams2008/Zoology/Summer/ZY4019Sum08.pdf
exams2010/Zoology/Summer/ZY4019Sum2010.pdf
exams2011/Zoology/Summer/ZY4019Sum2011.pdf
exams2012/Zoology/Summer/ZY4019Sum2012.pdf
exams2013/Zoology/Summer/ZY4019Sum2013.pdf
exams2014/Zoology/Summer/ZY4019Sum2014.pdf
I'm clearly doing something wrong here, but related questions don't address this specific condition (third sort criterion, subfield, numeric, reverse) and I can't identify a reason why it fails.
sort -t/ -k4
. That sort key is different for all lines, so no other key are considered.sort -t/ -k3,3 -k1,1r