linux系统中sort命令

 

linux系统中sort命令。

1、测试数据

[root@centos7 test2]# cat a.txt
google 110 5000
baidu 100 5000
guge 50 3000
sohu 100 4500

 

2、默认按照第一列排序

[root@centos7 test2]# sort a.txt
baidu 100 5000
google 110 5000
guge 50 3000
sohu 100 4500

 

3、按照第二列进行排序

[root@centos7 test2]# cat a.txt
google 110 5000
baidu 100 5000
guge 50 3000
sohu 100 4500
[root@centos7 test2]# sort -t " " -k 2n a.txt    ## -t指定分隔符,-k 2 指定列数, n表示按照数值大小进行排序
guge 50 3000
baidu 100 5000
sohu 100 4500
google 110 5000

 

4、先按照第二列排序,在按照第三列排序

[root@centos7 test2]# cat a.txt
google 110 5000
baidu 100 5000
guge 50 3000
sohu 100 4500
[root@centos7 test2]# sort -t " " -k 2n -k 3n a.txt
guge 50 3000
sohu 100 4500
baidu 100 5000
google 110 5000

 

5、先按第三列降序排列,再按照第二列升序排列

[root@centos7 test2]# cat a.txt
google 110 5000
baidu 100 5000
guge 50 3000
sohu 100 4500
[root@centos7 test2]# sort -t " " -k 3nr -k 2n a.txt    ## r表示逆向排序
baidu 100 5000
google 110 5000
sohu 100 4500
guge 50 3000

 

参考:https://www.cnblogs.com/longjshz/p/5797933.html

 

posted @ 2021-04-17 23:25  小鲨鱼2018  阅读(247)  评论(0编辑  收藏  举报