shell文本处理2:sort与uniq命令

1.sort命令:排序

参数:

-n	##纯数字排序
-r	##倒序
-u	##去掉重复数字
-o	##输出到指定文件中
-t	##指定分隔符
-k	##指定要排序的列
[[email protected] Desktop]# sort westos

shell文本处理2:sort与uniq命令

[[email protected] Desktop]# sort -n westos

shell文本处理2:sort与uniq命令

[[email protected] Desktop]# sort -u westos

shell文本处理2:sort与uniq命令

shell文本处理2:sort与uniq命令

[[email protected] Desktop]# sort -t : -k 2 westos

shell文本处理2:sort与uniq命令

[[email protected] Desktop]# sort -nt : -k 2 westos 

shell文本处理2:sort与uniq命令

[[email protected] Desktop]#  sort -nt : -k 2 westos -o /mnt/file 

shell文本处理2:sort与uniq命令

2.uniq命令:对重复字符处理

参数

-u	##显示唯一的行
-d	##显示重复的行
-c	##每行显示一次并统计重复次数

shell文本处理2:sort与uniq命令

[[email protected] Desktop]# sort -n westos | uniq -c
[[email protected] Desktop]# sort -n westos | uniq -d
[[email protected] Desktop]# sort -n westos | uniq -u

shell文本处理2:sort与uniq命令

练习

将/tmp目录中的文件取出最大的

[email protected] ~]$ ls -Sl /tmp/ | head -2 | cut -d " " -f 9