uniq命令


bash&shell系列文章:http://www.cnblogs.com/f-ck-need-u/p/7048359.html


uniq是去重,不相鄰的行不算重復值。

uniq [OPTION]... [INPUT [OUTPUT]]

選項說明:

-c:統計出現的次數(count)。

-d:只顯示被計算為重復的

-D:顯示所有被計算為重復的

-u:顯示唯一值,即沒有重復值的

-i:忽略大小寫。

-z:在末尾使用\0,而不是換行符。

-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.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM