linux uniq命令用法

2021-04-30 21:17:08 字數 2027 閱讀 5201

linux uniq命令用法

接下來通過實踐例項說明:

****************************************===

[root@stu100 ~]# cat test

boy took bat home

boy took bat home

girl took bat home

boy took bat home

boy took bat home

dog brought hat home

dog brought hat home

dog brought hat home

看test檔案的內容

****************************************====

[root@stu100 ~]# uniq test

boy took bat home

girl took bat home

boy took bat home

dog brought hat home

uniq命令不加任何引數,僅顯示連續重複的行一次

****************************************====

[root@stu100 ~]# uniq -c test

2 boy took bat home

1 girl took bat home

2 boy took bat home

3 dog brought hat home

-c 引數顯示檔案中每行連續出現的次數。

****************************************====

[root@stu100 ~]# cat test |sort | uniq -c 

4 boy took bat home

3 dog brought hat home

1 girl took bat home

排序後再顯示

****************************************====

[root@stu100 ~]# uniq -d test

boy took bat home

boy took bat home

dog brought hat home

-d選項僅顯示檔案中連續重複出現的行。

****************************************====

[root@stu100 ~]# uniq -u test

girl took bat home

-u選項顯示檔案中沒有連續出現的行。

****************************************====

[root@stu100 ~]# uniq -f 2 -s 2 test

boy took bat home

忽略每行的前2個字段,忽略第二個空白字元和第三個欄位的首字元,結果at home

****************************************====

[root@stu100 ~]# uniq -f 1 test

boy took bat home

dog brought hat home

忽略每行的第乙個字段,這樣boy ,girl開頭的行看起來是連續重複的行。

****************************************====

[root@stu100 ~]# uniq -d test

boy took bat home

boy took bat home

boy took bat home

boy took bat home

dog brought hat home

dog brought hat home

dog brought hat home

顯示所有重複的行,每個重複的行都顯示

linux uniq命令用法

uniq命令 對指定的ascii檔案或標準輸入進行唯一性檢查,以判斷文字檔案中重複出現的行,常用於分析日誌 檢視tcp各個狀態連線數,ip或網域名稱連線數排名等等場景,一般與 sort 命令結合使用。命令格式 uniq 選項 檔案1 檔案2 uniq從已經排好序的文字檔案file1中刪除重複的行,輸...

linux uniq命令詳解

linux uniq命令詳解 用uniq命令可以刪除相鄰的重複行 uniq file 但如果一文字中有重複卻不相鄰的行則無法刪除,需要結合sort命令 sort file uniq 等效的sort命令是 sort u file 另外uniq命令有4個有用的選項 uniq d file 只輸出file...

linux uniq 命令詳解

uniq 命令 文字 uniq 是linux命令 用途 報告或刪除檔案中重複的行。語法 uniq c d u f fields s characters fields characters infile outfile 描述 uniq 命令刪除檔案中的重複行。uniq 命令讀取由 infile 引數...