How to sort strings that contain a common prefix and suffix numerically from Bash?

前端 未结 4 1691
旧时难觅i
旧时难觅i 2020-11-30 07:33

Here is a list of files:

some.string_100_with_numbers.in-it.txt
some.string_101_with_numbers.in-it.txt
some.string_102_with_numbers.in-it.txt
some.string_23_         


        
4条回答
  •  独厮守ぢ
    2020-11-30 07:47

    Try the following:

    sort -t '_' -k 2n
    
    • -t '_' (sets the delimiter to the underscore character)
    • -k 2n (sorts by the second column using numeric ordering)

    DEMO.

提交回复
热议问题