uniq命令详解
??
基礎命令學習目錄首頁
?
原文鏈接:http://man.linuxde.net/uniq
刪除重復行:
uniq file.txt sort file.txt | uniq sort -u file.txt只顯示單一行:
uniq -u file.txt sort file.txt | uniq -u統計各行在文件中出現的次數:
sort file.txt | uniq -c在文件中找出重復的行:
sort file.txt | uniq -d原文鏈接:https://www.cnblogs.com/f-ck-need-u/p/7454597.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 1112 2231 561 567使用-d -c統計重復行出現的次數。
[root@xuexi tmp]# sort uniq.txt | uniq -d -c3 1112 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.?
轉載于:https://www.cnblogs.com/machangwei-8/p/9570964.html
總結
- 上一篇: MyBatis逆向工程:根据table生
- 下一篇: 泰迪熊移动实现数据化人工智能 打造服务助