Linux uniq commands

Source: Internet
Author: User
& Amp; #65279; & amp; #65279; uinq is short for unique. I. description: checks and deletes the repeated rows and columns in a text file. syntax: uniq [-cdu] [-f & lt; Column & gt;] [-s & lt; character position & gt;] [-w & lt; character Location & gt;] [-- help] [-- version] [input file] [output file]  uinq is short for unique.
 
I. INTRODUCTION
 
Function description: checks and deletes repeated rows and columns in a text file.
 
 
 
II. Syntax
 
Syntax: uniq [-cdu] [-f <栏位> ] [-S <字符位置> ] [-W <字符位置> ] [-- Help] [-- version] [input file] [output file]
 
Note: uniq can check repeated columns in text files.
 
 
 
III. common parameters:
 
-C: in the output, add the number of times that the row appears in the file (count) at the beginning of each row ). It can replace-u and-d.
 
-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.
 
 
 
IV. instance details
 
The original uniq.txt text is as follows:
 
 
 
[Root @ umail39 tmp] # cat uniq.txt
 
This is a test
 
This is a test
 
This is a test
 
I love you
 
I love you
 
We are good
 
This is a pen
 
I do not know
 
This is a pen
 
Www.2cto.com
 
 
 
1. add the number of occurrences of the corresponding row to the front of each row, but only check the adjacent duplicate rows.
 
[Root @ umail39 tmp] # uniq-c uniq.txt
 
2 this is a test
 
1 This is a test
 
2 I love you
 
1 we are good
 
1 this is a pen
 
1 I do not know
 
1 this is a pen
 
 
 
 
 
2.-f 1 ignores the first column and checks for duplicates starting from the second field. the checks are case insensitive.
 
[Root @ umail39 tmp] # uniq-f 1-c uniq.txt
 
3 this is a test
 
2 I love you
 
1 we are good
 
1 this is a pen
 
1 I do not know
 
1 this is a pen
 
 
 
 
 
3. the first four characters are not considered during the check.
 
[Root @ umail39 tmp] # uniq-s 4-c uniq.txt
 
3 this is a test
 
2 I love you
 
1 we are good
 
1 this is a pen
 
1 I do not know
 
1 this is a pen
 
 
 
 
 
4. repeat the items and display them all.
 
[Root @ umail39 tmp] # uniq-u uniq.txt
 
This is a test
 
We are good
 
This is a pen
 
I do not know
 
This is a pen
 
 
 
 
 
5. content after 2nd characters in each line is not checked
 
[Root @ umail39 tmp] # uniq-w 2-c uniq.txt
 
2 this is a test
 
1 This is a test
 
2 I love you
 
1 we are good
 
1 this is a pen
 
1 I do not know
 
1 this is a pen


From the column andy572633

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.