簡明Linux命令列筆記:uniq

來源:互聯網
上載者:User
文章目錄
  • 參數
  • 選項
  • 樣本

顯示唯一的行

uniq [options] [input-file] [output-file]

 

uniq用於顯示它的輸入,對於連續的重複行只保留一行。如果檔案已排序,uniq就確保不會顯示相同的兩行

 

參數

如果沒有指定input-file,那麼uniq將從標準輸入中讀取資料。如果沒有指定output-file,那麼uniq將寫入到標準輸出中

 

選項

-c                  在行首顯示該行在輸入檔案中出現的次數

-d                  顯示重複出現的行的一個副本,不顯示沒有重複的行

-f                   比較時跳過前n列

-i                   比較行時忽略字元大小寫

-s n               忽略每行的前n個字元

-u                  僅顯示沒有重複出現的行

-w n               對每行第n個字元以後的內容不做比較

 

樣本

原檔案

$ cat test boy took bat homeboy took bat homegirl took bat homedog brought hat homedog brought hat homedog brought hat home

 

uniq
$ uniq testboy took bat homegirl took bat homedog brought hat home

僅顯示連續重複的行一次

 

uniq -c
$ uniq -c test       2 boy took bat home      1 girl took bat home      3 dog brought hat home

顯示檔案中每行連續出現的次數

 

uniq -d
$ uniq -d testboy took bat homedog brought hat home

只顯示重複出現的行

 

uniq -u
$ uniq -u test girl took bat home

只顯示沒有連續重複出現的行

 

uniq -f -s
$ uniq -f 2 -s 2 test boy took bat home

跳過指定的列和字元進行比較

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.