uniq

英 [juˈni:k]   美 [juˈnik]  

adj.唯一的,仅有的;独一无二的,独特的;不平常的,特别的;超绝

Linux uniq命令 语法

作用:uniq命令用于检查及删除文本文件中重复出现的行列。

语法:uniq [-cdu][-f<栏位>][-s<字符位置>][-w<字符位置>][--help][--version][输入文件][输出文件]

Linux uniq命令 示例

文件testfile中第2 行、第5 行、第9 行为相同的行,使用uniq 命令删除重复的行,可使用以下命令:

uniq testfile

testfile中的原有内容为:

$ cat testfile      #原有内容  
test 30  
test 30  
test 30  
Hello 95  
Hello 95  
Hello 95  
Hello 95  
Linux 85  
Linux 85

使用uniq 命令删除重复的行后,有如下输出结果:

$ uniq testfile     #删除重复行后的内容  
test 30  
Hello 95  
Linux 85

检查文件并删除文件中重复出现的行,并在行首显示该行重复出现的次数。使用如下命令:

uniq-c testfile

结果输出如下:

$ uniq-ctestfile      #删除重复行后的内容  
3 test 30             #前面的数字的意义为该行共出现了3次  
4 Hello 95            #前面的数字的意义为该行共出现了4次  
2 Linux 85            #前面的数字的意义为该行共出现了2次

热门推荐