Linux Shell學習:uniq命令使用方法介紹uniq命令的作用:顯示唯一的行,對於那些連續重復的行只顯示一次!接下來通過實踐實例說明. [關鍵字] Linux Shell uniq
看test.txt文件的內容,可以看到其中的連續重復行
[root@hexu.org ~]# cat test.txt
boy took bat home
boy took bat home
girl took bat home
dog brought hat home
dog brought hat home
dog brought hat home
uniq命令不加任何參數,僅顯示連續重復的行一次
[root@hexu.org ~]# uniq test.txt
boy took bat home
girl took bat home
dog brought hat home
-c 參數顯示文件中每行連續出現的次數。
[root@hexu.org ~]# uniq -c test.txt
2 boy took bat home
1 girl took bat home
3 dog brought hat home
-d選項僅顯示文件中連續重復出現的行。
[root@hexu.org ~]# uniq -d test.txt
boy took bat home
dog brought hat home
-u選項顯示文件中沒有連續出現的行。
[root@hexu.org ~]# uniq -u test.txt
girl took bat home
忽略每行的前2個字段,忽略第二個空白字符和第三個字段的首字符,結果at home
[root@hexu.org ~]# uniq -f 2 -s 2 test.txt
boy took bat home
忽略每行的第一個字段,這樣boy ,girl開頭的行看起來是連續重復的行。
[root@hexu.org ~]# uniq -f 1 test.txt
boy took bat home
dog brought hat home