Bash/Linux Sort by 3rd column using custom field seperator

后端 未结 3 653
梦谈多话
梦谈多话 2021-01-16 18:20

I can\'t seem to sort the following data as I would like;

find output/ -type f -name *.raw | sort 
output/rtp.0.0.raw
output/rtp.0.10.raw
output/rtp.0.11.raw         


        
3条回答
  •  说谎
    说谎 (楼主)
    2021-01-16 18:42

    Fedorqui's solution is good (+1), but not all versions of sort support -V. For those versions that do not, you need to do a little more work than fedorqui's original solution. This should suffice:

    sort -t. -k2,2 -k3,3 -n
    

    You get a slightly different sort (eg, '05' sorts before '1' instead of after) if you use:

    sort -t. -k2g
    

    (Note that -g is also non-standard, and not available in all versions of sort).

提交回复
热议问题