阅读目录
- uniq命令:
uniq命令:
常见参数:
-c,–count *****
在每行旁边显示改行重复出现的次数
-d,–repeated
仅显示重复出现的行,2次或2次以上的行,默认的去重包含1次。
例子:
a.只对相邻的相同行内容去重。
[root@nfs-server test]# cat test.txt
10.0.0.9
10.0.0.8
10.0.0.7
10.0.0.7
10.0.0.8
10.0.0.8
10.0.0.9
[root@nfs-server test]# uniq test.txt
10.0.0.9
10.0.0.8
10.0.0.7
10.0.0.8
10.0.0.9
b.sort命令让重复的行相邻
[root@nfs-server test]# sort test.txt
10.0.0.7
10.0.0.7
10.0.0.8
10.0.0.8
10.0.0.8
10.0.0.9
10.0.0.9
c.先用sort命令将重复的行相邻,接着使用uniq去重
[root@nfs-server test]# sort test.txt|uniq
10.0.0.7
10.0.0.8
10.0.0.9
[root@nfs-server test]#
d.将两个命令整合起来,可使用sort -u代替
[root@nfs-server test]# sort -u test.txt
10.0.0.7
10.0.0.8
10.0.0.9<