Sort passwd file by 3rd field.
$ sort -t: -k 3n /etc/passwd | more
testdeMacBook-Air:~ test$ cat 1 one:2:3 two:2:1 three:3:2 testdeMacBook-Air:~ test$ sort -t: -k 3rn 1 one:2:3 three:3:2 two:2:1 testdeMacBook-Air:~ test$ sort -t: -k 3n 1 two:2:1 three:3:2 one:2:3 testdeMacBook-Air:~ test$
按数字进行排序
sort -n file.txt
按逆序进行排序
sort -r file.txt
cat data.txt
1 mac 2000
2 winxp 4000
3 bsd 1000
4 linux 1000
依据第1列,以逆序形式排序
sort -nrk 1 data.txt
4 linux 1000
3 bsd 1000
2 winxp 4000
1 mac 2000
-nr表明按照数字,采用逆序形式排序
依据第2列进行排序
sort -k 2 data.txt
3 bsd 1000
4 linux 1000
1 mac 2000
2 winxp 4000