uniq
英 [ju?ni:k]? ?美 [ju?nik]??
adj.唯一的,僅有的;獨一無二的,獨特的;不平常的,特別的;超絕
Linux uniq命令 語法
作用:uniq命令用于檢查及刪除文本文件中重復出現(xiàn)的行列。
語法:uniq [-cdu][-f<欄位>][-s<字符位置>][-w<字符位置>][--help][--version][輸入文件][輸出文件]
Linux uniq命令 示例
文件testfile中第2 行、第5 行、第9 行為相同的行,使用uniq 命令刪除重復的行,可使用以下命令:
uniq testfile
testfile中的原有內容為:
$ cat testfile #原有內容 test 30 test 30 test 30 Hello 95 Hello 95 Hello 95 Hello 95 Linux 85 Linux 85
使用uniq 命令刪除重復的行后,有如下輸出結果:
$ uniq testfile #刪除重復行后的內容 test 30 Hello 95 Linux 85
檢查文件并刪除文件中重復出現(xiàn)的行,并在行首顯示該行重復出現(xiàn)的次數(shù)。使用如下命令:
uniq-c testfile
結果輸出如下:
$ uniq-ctestfile #刪除重復行后的內容 3 test 30 #前面的數(shù)字的意義為該行共出現(xiàn)了3次 4 Hello 95 #前面的數(shù)字的意義為該行共出現(xiàn)了4次 2 Linux 85 #前面的數(shù)字的意義為該行共出現(xiàn)了2次