uniq是去重,不相鄰的行不算重複值。less
uniq [OPTION]... [INPUT [OUTPUT]]spa
選項說明:code
-c:統計出現的次數(count)。orm
-d:只顯示被計算爲重複的行。blog
-D:顯示全部被計算爲重複的行。排序
-u:顯示惟一值,即沒有重複值的行。io
-i:忽略大小寫。form
-z:在末尾使用\0,而不是換行符。class
-f:跳過多少個字段(field)開始比較重複值。統計
-s:跳過多少個字符開始比較重複值。
-w:比較重複值時每行比較的最大長度。即對每行多長的字符進行比較。
示例:
[root@xuexi tmp]# cat uniq.txt 111 223 56 111 111 567 223
下面的命令刪除了相鄰的重複行,可是第一行111沒有刪除。
[root@xuexi tmp]# uniq uniq.txt 111 223 56 111 # 刪除了重複的111 567 223
排序後去重。
[root@xuexi tmp]# sort uniq.txt | uniq 111 223 56 567
使用-d顯示重複的行。
[root@xuexi tmp]# sort uniq.txt | uniq -d 111 223
使用-D顯示全部重複過的行。
[root@xuexi tmp]# sort uniq.txt | uniq -D 111 111 111 223 223
使用-u顯示惟一行。
[root@xuexi tmp]# sort uniq.txt | uniq -u 56 567
使用-c統計哪些記錄出現的次數。
[root@xuexi tmp]# sort uniq.txt | uniq -c 3 111 2 223 1 56 1 567
使用-d -c統計重複行出現的次數。
[root@xuexi tmp]# sort uniq.txt | uniq -d -c 3 111 2 223
-c不能和-D一塊兒使用。結果說顯示全部重複行再統計重複次數是毫無心義的行爲。
[root@xuexi tmp]# sort uniq.txt | uniq -D -c uniq: printing all duplicated lines and repeat counts is meaningless Try `uniq --help' for more information.