Using GNU sort. I want to print only the first of a group of lines, based on duplicate key(s).
-k1,2 works as expected – only the 1st sorted line is output
printf %s\\n 'a a c' 'a a b' 'a a a' | sort -u -k1,2 -t' ' # a a a
-k1 does not work as expected – all 3 sorted lines are output
printf %s\\n 'a a c' 'a a b' 'a a a' | sort -u -k1 -t' ' # a a a # a a b # a a c
Is this normal for all variants of
sort, or is it just GNU sort?
It seems rather prone to 'unexpected results', as
man sort shows the 2nd key number as optional:
-k1,1 does work with
-u, wheras a plain sort (ie. no
-u) works with just