Linux Shell script programming-uniq command

Source: Internet
Author: User
Uniq

The uniq command can remove duplicate rows from sorted files. Therefore, uniq is often used with sort. That is to say, to make uniq work, all repeated rows must be adjacent.

Uniq syntax

[Root @ WWW ~] # Uniq [-ICU] Option and parameter:-I: Ignore case-insensitive characters;-C: Count-u: show only unique rows

 

The content of testfile is as follows:

Cat testfilehelloworldfriendhelloworldhello

 

Directly Delete unordered files. No rows are deleted.

# Uniq testfile helloworldfriendhelloworldhello

 

Sort files. deduplication is used by default.

# Cat words | sort | uniqfriendhelloworld

 

Duplicate rows are deleted after sorting, and the number of repeated rows is output at the beginning of the row.

# Sort testfile | uniq-C1 friend3 hello2 world

 

Only duplicate rows are displayed, and the number of repeated rows is displayed at the beginning of the row.

# Sort testfile | uniq-DC3 hello2 world

 

Only show non-repeated rows

Sort testfile | uniq-ufriend

 

Related Article

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.