sort--命令详解

sort:文本排序   

功能说明:将文件内容按照指定的规则进行排序,然后将排序结果输出。

语法格式:

sort 【option】 【file】

sort   选项            文件

参数:-n 依照数值的大小进行排序

[root@template ~ 23:36:07]]# cat test.txt
10.0.0.4
10.0.0.4
10.0.0.4
10.0.0.5
10.0.0.4
10.0.0.8
[root@template ~ 23:36:12]]# sort -n test.txt   #按照数字大小从小到大排序
10.0.0.4
10.0.0.4
10.0.0.4
10.0.0.4
10.0.0.5
10.0.0.8

参数:-r 倒序排序

[root@template ~ 23:36:19]]# sort -rn test.txt
10.0.0.8
10.0.0.5
10.0.0.4
10.0.0.4
10.0.0.4
10.0.0.4

参数:-u 去除重复行

[root@template ~ 23:37:33]]# sort -u test.txt
10.0.0.4
10.0.0.5
10.0.0.8

参数:-t 指定分隔符

[root@template ~ 23:49:15]]# sort -t " " -k2 test1.txt  #指定以空格为分隔符,按照第二列进行排序
10.0.0.4 a
10.0.0.4 g
10.0.0.8 l
10.0.0.5 n
10.0.0.4 q
10.0.0.4 r

参数:-k 按指定区间排序

[root@template ~ 23:49:02]]# sort -k2 test1.txt  #按照第二列排序
10.0.0.4      a
10.0.0.4      g
10.0.0.8       l
10.0.0.5      n
10.0.0.4      q
10.0.0.4       r

 

posted on 2021-02-28 23:54  弓长三寿  阅读(558)  评论(0)    收藏  举报