Sorting on the last field of a line

后端 未结 11 1021
暗喜
暗喜 2020-12-05 04:06

What is the simplest way to sort a list of lines, sorting on the last field of each line? Each line may have a variable number of fields.

Something like



        
11条回答
  •  无人及你
    2020-12-05 04:53

    | sed "s#(.*)/#\1"\\$'\x7F'\# \
    | sort -t\\$'\x7F' -k2,2 \
    | sed s\#\\$'\x7F'"#/#"
    

    Still way worse than simple negative field indexes for sort(1) but using the DEL character as delimiter shouldn’t cause any problem in this case.

    I also like how symmetrical it is.

提交回复
热议问题