-n --numeric-sort compare according to string numerical value 以純數字排序 (默認以文本類型排序)
$ cat a 11 32 5 1 4 3 $ sort a 1 11 3 32 4 5 $ sort -n a 1 3 4 5 11 32 -u --unique 相同的數據中,僅出現一行 $ cat a 1 3 5 1 3 $ sort -u a 1 3 5
指定排序的區間
以冒號":"作為分隔符的第一個字段排序
head /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/bin/sh bin:x:2:2:bin:/bin:/bin/sh sys:x:3:3:sys:/dev:/bin/sh sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/bin/sh man:x:6:12:man:/var/cache/man:/bin/sh lp:x:7:7:lp:/var/spool/lpd:/bin/sh mail:x:8:8:mail:/var/mail:/bin/sh news:x:9:9:news:/var/spool/news:/bin/sh $ head /etc/passwd| sort -t ":" -k 1 bin:x:2:2:bin:/bin:/bin/sh daemon:x:1:1:daemon:/usr/sbin:/bin/sh games:x:5:60:games:/usr/games:/bin/sh lp:x:7:7:lp:/var/spool/lpd:/bin/sh mail:x:8:8:mail:/var/mail:/bin/sh man:x:6:12:man:/var/cache/man:/bin/sh news:x:9:9:news:/var/spool/news:/bin/sh root:x:0:0:root:/root:/bin/bash sync:x:4:65534:sync:/bin:/bin/sync sys:x:3:3:sys:/dev:/bin/sh 以下這個例子可以看出-n的重要性了 $ cat a pa:11:a sa:32:c app:5:b stort:1:d pear:4:aa hello:3:f $ cat a |sort -t ":" -k 2 pa:11:a stort:1:d sa:32:c hello:3:f pear:4:aa app:5:b $ cat a |sort -t ":" -k 2 -n stort:1:d hello:3:f pear:4:aa app:5:b pa:11:a sa:32:c