Linux uniq command
Translation results:
uniq
英[juˈni:k] 美[juˈnik]
adj. Only, only; unique, unique; unusual , special; extraordinary
Linux uniq commandsyntax
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 commandexample
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 #原有内容 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 #删除重复行后的内容 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 #删除重复行后的内容 3 test 30 #前面的数字的意义为该行共出现了3次 4 Hello 95 #前面的数字的意义为该行共出现了4次 2 Linux 85 #前面的数字的意义为该行共出现了2次