【Linux】循序渐进学运维 - uniq篇

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
发布了29 篇原创文章 · 获赞 6 · 访问量 2742

猜你喜欢

转载自blog.csdn.net/SKTONE_SHUAI/article/details/104355197