uniq
英[ju?ni:k] 美[ju?nik]
adj. Only, only; unique, unique; unusual , special; extraordinary
Linux uniq command syntax
Function: uniq command is used to check and delete repeated rows and columns in text files.
Syntax: uniq [-cdu][-f<field>][-s<Character position>][-w<Character position>][--help ][--version][input file][output file]
Linux uniq command example
Lines 2, 5, and 9 in the file testfile are the same lines. Use the uniq command to delete duplicate lines. You can use the following command:
uniq testfile
The original content in testfile is:
$ cat testfile #原有內(nèi)容 test 30 test 30 test 30 Hello 95 Hello 95 Hello 95 Hello 95 Linux 85 Linux 85
After using the uniq command to delete duplicate lines, the following output will appear:
$ uniq testfile #刪除重復(fù)行后的內(nèi)容 test 30 Hello 95 Linux 85
Check the file and delete the repeated lines in the file, and display the number of repeated lines at the beginning of the line. Use the following command:
uniq-c testfile
The result output is as follows:
$ uniq-ctestfile #刪除重復(fù)行后的內(nèi)容 3 test 30 #前面的數(shù)字的意義為該行共出現(xiàn)了3次 4 Hello 95 #前面的數(shù)字的意義為該行共出現(xiàn)了4次 2 Linux 85 #前面的數(shù)字的意義為該行共出現(xiàn)了2次