Linux 命令 uniq 通知或忽略重複行

2022-03-21 23:19:19 字數 1402 閱讀 1224

給定乙個已排好序的檔案,uniq 會刪除重複行並將結果輸出到標準輸出中。uniq 通常與 sort 結合使用以刪除 sort 輸出內容中的重複行。

uniq [option]... [input [output]]

-c, --count

輸出重複行列表,並且重複行前面加上其出現的次數。

-d, --repeated

只輸出重複行。

-f, --skip-fields=n

忽略每行前 n 個字段。欄位以空格隔開,這與 sort 類似,但不能提供引數設定可選擇的字段分隔符。

-i, --ignore-case

比較時不區分大小寫。

-s, --skip-chars=n

忽略每行的前 n 個字元。

-u, --unique

僅輸出不重複行,這是預設的選項。

-z, --zero-terminated

以 0 位元組而非新行作為行尾標誌。

-w, --check-chars=n

只對前 n 個字元作比較。

--help

顯示幫助資訊。

--version

顯示版本資訊。

測試檔案 testfile:

good bye

good bye

hello world

hello world

how do you do

long time no see

long time no see

long time no see

this is a test file

this is a test file

a) 忽略重複行。

[huey@huey-k42je cmdline]$ uniq testfile 

good bye

hello world

how do you do

long time no see

this is a test file

b) 忽略重複行,並在每行前顯示重複數。

[huey@huey-k42je cmdline]$ uniq -c testfile 

2 good bye

2 hello world

1 how do you do

3 long time no see

2 this is a test file

c) 僅輸出有重複的行。

[huey@huey-k42je cmdline]$ uniq -d testfile 

good bye

hello world

long time no see

this is a test file

Linux命令詳解 Uniq

本次我們來學習一下uniq shell 命令,wiki見這裡 wiki的結果比較簡單,我們可以直接在系統上先man一下看下結果 uniq report or omit repeated lines 這個摘要很有一下,注意是report or omit,也就是說既能顯示某些資訊,也能忽略某些資訊,後者...

Linux 命令(7) uniq 命令

用於去除有序檔案中的重複行並將結果輸出到標準輸出。為了使uniq 起作用,所有的重複行必須是相鄰的,所以 uniq 經常和 sort 合用。uniq option input output c,count 顯示行出現的次數 d,repeated 僅顯示重複出現的行,即出現次數 2 的行,且只列印一次...

Linux的uniq命令詳解

linux命令uniq的作用是過濾重複部分顯示檔案內容,這個命令讀取輸入檔案,並比較相鄰的行。在正常情況下,第二個及以後更多個重複行將被刪去,行比較是根據所用字符集的排序序列進行的。該命令加工後的結果寫到輸出檔案中。輸入檔案和輸出檔案必須不同。如果輸入檔案用 表示,則從標準輸入讀取。uniq 選項 ...