uniq 命令可以删除排序过的文件中的重复行,因此uniq经常和sort合用。
也就是说,为了使uniq起作用,所有的重复行必须是相邻的。
选项与参数
-i :忽略大小写字符的不同;
-c :进行计数
-u :只显示唯一的行
示例:
[root@ localhost ~]# cat quchong.txt
one
one
two
three
four
four
1.排序之后删除了重复行,同时在行首位置输出该行重复的次数
[root@ localhost ~]# sort quchong.txt |uniq -c
2 four
2 one
1 three
1 two
2.仅显示存在重复的行,并在行首显示该行重复的次数
[root@ localhost ~]# sort quchong.txt |uniq -dc
2 four
2 one
3.仅显示不重复的行
[root@ localhost ~]# sort quchong.txt |uniq -u
three
two