Sorting 1 before 10 in bash

后端 未结 2 1797
予麋鹿
予麋鹿 2021-01-24 22:08

I\'m sorting numerically on a specific column of a ; separated file with:

sort -k3n file

But numbers 10 and 11 are sorted before 1

相关标签:
2条回答
  • 2021-01-24 23:09

    The -n option should do the trick. Can you check that this doesn't output the order you want?

    echo -e "1\n10\n11\n2"|sort -n
    
    0 讨论(0)
  • 2021-01-24 23:14

    If your fields are separated with something else than a blank, you can use the --field-separator or -t option, like so:

    sort -k3n -t\; file
    
    0 讨论(0)
提交回复
热议问题