Chinaunix首页 | 论坛 | 博客
  • 博客访问: 783547
  • 博文数量: 104
  • 博客积分: 915
  • 博客等级: 下士
  • 技术积分: 2171
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-24 21:34
文章分类

全部博文(104)

文章存档

2018年(4)

2015年(14)

2014年(9)

2013年(56)

2012年(21)

分类: 系统运维

2015-11-15 22:57:02

参考博客:http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858385.html

该命令可以去除排序过的文件中的重复行,因此uniq经常和sort合用。也就是说,为了使uniq起作用,所有的重复行必须是相邻的。

uniq语法

[root@www ~]# uniq [-icu]
选项与参数: 
    -i:忽略大小写字符的不同; 
    -c:进行计数 
    -u:只显示唯一的行

testfile的内容如下

复制代码
cat testfile
hello
world
friend
hello
world
hello
复制代码

直接删除未经排序的文件,将会发现没有任何行被删除

复制代码
#uniq testfile  
hello
world
friend
hello
world
hello
复制代码

排序文件,默认是去重

#cat words | sort |uniq 
friend
hello
world

排序之后删除了重复行,同时在行首位置输出该行重复的次数

#sort testfile | uniq -
1 friend 
3 hello 
2 world

仅显示存在重复的行,并在行首显示该行重复的次数

#sort testfile | uniq -dc 
3 hello 
2 world

仅显示不重复的行

sort testfile | uniq -u
friend 
阅读(832) | 评论(0) | 转发(0) |
0

上一篇:sort排序

下一篇:cut

给主人留下些什么吧!~~