Linux uniq command Introduction

Source: Internet
Author: User

Address: http://blog.csdn.net/zzxian/article/details/7200046

Uniq [Option] File

Note: This command reads the input file and compares adjacent lines. Under normal circumstances, the second and later repeated rows are deleted, and the row comparison is performed based on the sorting sequence of the character set used. The result after processing the command is written to the output file. The input and output files must be different. If the input file is expressed as "-", it is read from the standard input.

The options of this command are as follows :,

-C: In the output, add the number of times this row appears in the file at the beginning of each row. It can replace the-u and-d options.

-D: only duplicate rows are displayed.

-U only displays rows that are not repeated in the file.

-N the first n fields are ignored together with the blank space before each field. A field is a non-space, non-tab string, separated by tabs and spaces (the Field starts from 0 ).

+ N the first n characters are ignored, and the previous characters are skipped (the characters start from 0 ).

-F n is the same as-n, where n is the number of fields.

-S n is the same as + n, where n is the number of characters.

The following example shows how to use it:

========================================================== ===

[root@stu100 ~]# cat testboy took bat homeboy took bat homegirl took bat homeboy took bat homeboy took bat homedog brought hat homedog brought hat homedog brought hat home

View the content of the test File

========================================================== ====

[root@stu100 ~]# uniq testboy took bat homegirl took bat homeboy took bat homedog brought hat home

The uniq command only displays duplicate rows once without adding any parameters.

========================================================== ====

[root@stu100 ~]# uniq -c test2 boy took bat home1 girl took bat home2 boy took bat home3 dog brought hat home1

-The c parameter shows the number of consecutive occurrences of each row in the file.

========================================================== ====

[root@stu100 ~]# cat test |sort | uniq -c14 boy took bat home3 dog brought hat home1 girl took bat home

Display after sorting

========================================================== ====

[root@stu100 ~]# uniq -d testboy took bat homeboy took bat homedog brought hat home

-D option only displays the rows that repeatedly appear in the file.

========================================================== ====

[root@stu100 ~]# uniq -u testgirl took bat home

-U option shows that there are no consecutive rows in the file.

========================================================== ====

[root@stu100 ~]# uniq -f 2 -s 2 testboy 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 testboy took bat homedog brought hat home

Ignore the first field in each line. In this way, the line starting with "boy" and "girl" appears to be a row that repeats continuously.

========================================================== ====

[root@stu100 ~]# uniq -D testboy took bat homeboy took bat homeboy took bat homeboy took bat homedog brought hat homedog brought hat homedog brought hat home

Show all duplicate rows.

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.