& Nbsp; uniq command: display unique Rows. only one row is displayed for those rows that are repeated consecutively! Next, we will explain through practical examples: [root @ stu100 ~] # Cattestboytookbathomeboytookbathomegirltookbathomedogbroughthathomedog
Uniq command: displays unique Rows. only one row is displayed for repeated rows!
The following example shows how to use it:
[Root @ stu100 ~] # Cat test
Boy took bat home
Boy took bat home
Girl took bat home
Dog brought hat home
Dog brought hat home
Dog brought hat home
View the content of the test file, and you can see the repeated rows.
[Root @ stu100 ~] # Uniq test
Boy took bat home
Girl took bat home
Dog brought hat home
The uniq command only displays duplicate rows once without adding any parameters.
[Root @ stu100 ~] # Uniq-c test
2 boy took bat home
1 girl took bat home
3 dog brought hat home
-The c parameter shows the number of consecutive occurrences of each row in the file.
[Root @ stu100 ~] # Uniq-d test
Boy took bat home
Dog brought hat home
-D option only displays the rows that repeatedly appear in the file.
[Root @ stu100 ~] # Uniq-u test
Girl took bat home
-U option shows that there are no consecutive rows in the file.
[Root @ stu100 ~] # Uniq-f 2-s 2 test
Boy took bat home
Ignore the first two fields of each line, ignore the first character of the second blank character and the third field, and the result is at home
[Root @ stu100 ~] # Uniq-f 1 test
Boy took bat home
Dog brought hat home
Ignore the first field of each line. in this way, the line starting with "boy" and "girl" appears to be a row that repeats continuously.