1. Function: Output or delete duplicate rows, but the same row will be in the adjacent row
2. Syntax:uniq [OPTION] ... [INPUT [OUTPUT]]
3. Parameters:
-C,--count shows the number of occurrences of recurrence next to each column
-D,--repeated show only recurring rows
-D,--all-repeated[=delimit-method] Displays all occurrences of duplicate rows
-F,--skip-fields=n skip the first N rows
-I,--ignore-case ignore case
-S,--skip-chars=n skips the first N characters
-U,--unique prints only the only rows that appear
-W Specifies the characters to compare
4. Example
1. In the case of unsorted, direct use of the Uniq command does not view duplicate rows.
[Email protected] ~]$ Uniq week.txt
Mon
Tue
Wed
Thu
Fri
Mon
Tue
Wed
Thu
Fri
Mon
Tue
Wed
Thu
Fri
2. After using sorting, you can use Uniq to remove duplicate rows.
[Email protected] ~]$ sort week.txt |uniq
Fri
Fri
Mon
Mon
Thu
Thu
Tue
Tue
Wed
Wed
3. After using the-i parameter, the number of rows displayed is even less.
[Email protected] ~]$ sort Week.txt |uniq-i
Fri
Mon
Thu
Tue
Wed
4. With the-c parameter, the number of occurrences per row appears next to each column.
[Email protected] ~]$ sort week.txt |uniq-i-C
3 Fri
3 Mon
3 Thu
3 Tue
3 Wed
5. To test the-D parameter, add the SAT and Sun in the Week.txt file
[Email protected] ~]$ sort Week.txt |uniq-i
Fri
Mon
Sat
Sun
Thu
Tue
Wed
[Email protected] ~]$ sort week.txt |uniq-i-D
Fri
Mon
Thu
Tue
Wed
6. With the-d parameter, all duplicate rows are displayed, while sat and Sun are not displayed.
[Email protected] ~]$ sort week.txt |uniq-i-D
Fri
Fri
Fri
Mon
Mon
Mon
Thu
Thu
Thu
Tue
Tue
Tue
Wed
Wed
Wed
7. Use-U only shows sat and sun two lines
[Email protected] ~]$ sort Week.txt |uniq-i-u
Sat
Sun
This article is from the "three countries Cold jokes" blog, please be sure to keep this source http://myhwj.blog.51cto.com/9763975/1794001
Linux Common Commands--uniq