When using the sort
function in a shell, it seems the preferred syntax for the -k
option when sorting via only one field is, for example, -k5n,5
. What's the advantage of the ,5
in this case? -k5n
works the same, or at least seems to for me.
Refs:
Assume your data has N
fields. -k5n
is equivalent to -k5,Nn
, meaning the data will be sorted using fields 5 through N
as the key. This may not be desirable, for instance if you want a stable sort that doesn't modify the relative order of records in the input with equal values for the 5th field. Using -k5,5n
makes it explicit that you want to sort on the 5th field alone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With