shell工具-sort

sort

sort命令是在Linux里非常有用,它将文件进行排序,并将排序结果标准输出

基本语法

sort [选项] [参数]

选项说明

选项说明
-n 依照数值大小排序
-r 以相反的顺序排序
-t 设置排序时所用的分割字符
-k 指定需要排序的列

案例实操

数据准备

[root@slave2 testshell]# touch sort.txt
[root@slave2 testshell]# vim sort.txt 
bb:40:5.4
db:20:4.2
xz:50:2.3
cls:10:3.5
ss:30:1.6

按照第三列排序

[root@slave2 testshell]# sort -t: -nk 3 sort.txt  
ss:30:1.6
xz:50:2.3
cls:10:3.5
db:20:4.2
bb:40:5.4
[root@slave2 testshell]# sort -t: -rk 3 sort.txt  
bb:40:5.4
db:20:4.2
cls:10:3.5
xz:50:2.3
ss:30:1.6

 

posted on 2019-02-23 09:48  0x153_小波  阅读(139)  评论(0编辑  收藏  举报