Linux Common Commands--uniq

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.