uniq 去除重複命令使用方法介紹

2022-07-12 20:24:18 字數 1123 閱讀 6991

linux shell學習:uniq命令使用方法介紹uniq命令的作用:顯示唯一的行,對於那些連續重複的行只顯示一次!接下來通過實踐例項說明. [關鍵字] linux shell uniq

看test.txt檔案的內容,可以看到其中的連續重複行

[[email protected] ~]#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命令不加任何引數,僅顯示連續重複的行一次

[[email protected] ~]#uniq test.txt

boy took bat home

girl took bat home

dog brought hat home

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

[[email protected] ~]# uniq -c test.txt

2 boy took bat home

1 girl took bat home

3 dog brought hat home

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

[[email protected] ~]# uniq -d test.txt

boy took bat home

dog brought hat home

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

[[email protected] ~]# uniq -u test.txt

girl took bat home

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

[[email protected] ~]#uniq -f 2 -s 2 test.txt

boy took bat home

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

[[email protected] ~]# uniq -f 1 test.txt

boy took bat home

dog brought hat home

uniq命令使用方法

uniq命令的作用 顯示唯一的行,對於那些連續重複的行只顯示一次!接下來通過實踐例項說明 root stu100 cat test boy took bat home boy took bat home girl took bat home dog brought hat home dog brou...

python之random模組使用方法介紹

import random print random.random 0,1 float 大於0且小於1之間的小數 print random.randint 1,3 1,3 大於等於1且小於等於3之間的整數 print random.randrange 1,3 1,3 大於等於1且小於3之間的整數 p...

vi命令使用方法

vi替換命令用法詳解 ranges pat1 pat2 g 其中 這是 vi的命令執行介面。range 是命令執行範圍的指定 百分號 表示所有行 點 表示當前行 美元 表示最末行 例如 10,20表示第 10到20行,表示當前行到最後一行,2,5表示當前行後兩行直到全文的倒數第五行 s 表示其後是乙...