Linux系统中如何使用uniq命令删除文本重复行( 二 )


3 this is a test
1 i am tank
2 i love tank
1 this is a test
2 whom have a try
1 you have a try
1 i want to abroad
2 those are good men //只有一行,显示二行
在这里those只有一行,显示的却是重复了,这是因为,-f 1 忽略了第一列,检查重复从第二字段开始的 。
代码如下:
[zhangy@BlackGhost mytest]$ uniq -i -c uniqtest
3 this is a test
1 i am tank
2 i love tank
1 this is a test
2 whom have a try //一个大写,一个小写
1 you have a try
1 i want to abroad
1 those are good men
1 we are good men
检查的时候,不区分大小写
代码如下:
[zhangy@BlackGhost mytest]$ uniq -s 4 -c uniqtest
3 this is a test
1 i am tank
2 i love tank
1 this is a test
3 whom have a try //根上一个例子有什么不同
1 i want to abroad
1 those are good men
1 we are good men
检查的时候,不考虑前4个字符,这样whom have a try 就和 you have a try 就一样了 。
代码如下:
[zhangy@BlackGhost mytest]$ uniq -u uniqtest
i am tank
this is a test
whom have a try
WhoM have a try
you have a try
i want to abroad
those are good men
we are good men
去重复的项,然后全部显示出来
代码如下:
[zhangy@BlackGhost mytest]$ uniq -w 2 -c uniqtest
3 this is a test
3 i am tank
1 this is a test
1 whom have a try
1 WhoM have a try
1 you have a try
1 i want to abroad
1 those are good men
1 we are good men
对每行第2个字符以后的内容不作检查,所以i am tank 根 i love tank就一样了 。
上面就是Linux下使用uniq命令删除重复行命令的方法介绍了,有时文本中的重复行不仅没有用处,还占用空间,快使用uniq命令进行清除吧 。

推荐阅读