uniq - report or omit repeated lines 报告或者忽略重复的行
常用参数及说明:更多详细信息可以参考man uniq页面
-i:--ignore-case 忽略大小写
-c:count 进行计数
-d:--repeated 仅仅打印重复的行
例子:
[root@rhel6164 test]# cat test.txt #原始文件
one
two
three
one
one
three
two
one
[root@rhel6164 test]# cat test.txt | sort | uniq -c #忽略重复的行,并统计每一重复的行出现的次数
4 one
2 three
2 two
[root@rhel6164 test]# cat test.txt | uniq -c #如果在uniq之前不对文本进行sort排序,那么uniq就只比较相连的行是否是重复行
1 one
1 two
1 three
2 one
1 three
1 two
1 one
[root@rhel6164 test]# cat test.txt | uniq -d #仅仅打印重复的行,上下行进行比较
one