其他分享
首页 > 其他分享> > sort命令

sort命令

作者:互联网

 

1、

[root@WALKER tmp]# cat test.txt
1       b
2       r
9       t
7       r
8       g
4       f
2       s
8       l
7       r
4       f
[root@WALKER tmp]#

 

2、对文件第一个字符进行排序,默认从小到大

-n参数:

[root@WALKER tmp]# sort -n test.txt
1       b
2       r
2       s
4       f
4       f
7       r
7       r
8       g
8       l
9       t
[root@WALKER tmp]#

 

3、倒序排序

-r参数

[root@WALKER tmp]# sort -nr test.txt
9       t
8       l
8       g
7       r
7       r
4       f
4       f
2       s
2       r
1       b
[root@WALKER tmp]#

 

4、对排序结果去重(去掉重复值)

-u参数

 

 

5、指定分割符号,指定区域进行排序

指定分割符号:-t

指定区域:-k

[root@WALKER tmp]# cat test.txt
10.0.0.3
10.0.0.43
10.0.0.42
10.0.0.23
10.0.0.10
[root@WALKER tmp]# sort -n -t "." -k 4 test.txt
10.0.0.3
10.0.0.10
10.0.0.23
10.0.0.42
10.0.0.43
[root@WALKER tmp]#

 

标签:sort,tmp,0.0,命令,test,WALKER,txt,root
来源: https://www.cnblogs.com/zypdbk/p/16319016.html