Linux uniq命令

uniq是去重,不相邻的行不算重复值。

uniq [OPTION]... [INPUT [OUTPUT]]

选项说明:

示例:

[root@linuxidc tmp]# cat uniq.txt
111
223
56
111
111
567
223

下面的命令删除了相邻的重复行,但是第一行111没有删除。

[root@linuxidc tmp]# uniq uniq.txt
111
223
56
111   # 删除了重复的111
567
223

排序后去重。

[root@linuxidc tmp]# sort uniq.txt | uniq
111
223
56
567

使用-d显示重复的行。

[root@linuxidc tmp]# sort uniq.txt | uniq  -d
111
223

使用-D显示所有重复过的行。

[root@linuxidc tmp]# sort uniq.txt | uniq  -D
111
111
111
223
223

使用-u显示唯一行。

[root@linuxidc tmp]# sort uniq.txt | uniq  -u
56
567

使用-c统计哪些记录出现的次数。

[root@linuxidc tmp]# sort uniq.txt | uniq  -c  
      3 111
      2 223
      1 56
      1 567

使用-d -c统计重复行出现的次数。

[root@linuxidc tmp]# sort uniq.txt | uniq  -d -c
      3 111
      2 223

-c不能和-D一起使用。结果说显示所有重复行再统计重复次数是毫无意义的行为。

[root@linuxidc tmp]# sort uniq.txt | uniq  -D -c
uniq: printing all duplicated lines and repeat counts is meaningless
Try `uniq --help' for more information.

猜你喜欢

转载自www.linuxidc.com/Linux/2017-08/146608.htm