Detailed description of the instance in linux

Source: Internet
Author: User

In linux, the command uniq 1 is used to remove duplicate lines in the text of uniq, which is basically not what we want, so we need to remove them. There are other commands in linux that can remove repeated rows, But I think uniq is more convenient. When using uniq, pay attention to the following two points: 1. During text operations, it is generally used in combination with the sort command, because uniq does not check duplicate lines, unless they are adjacent rows. If you want to sort input first, use sort-u.
2. During text operations, if the domain is a null character (usually including spaces and tabs) and then a non-empty character, the blank character before the domain is skipped www.2cto.com 2, uniq parameter description [zhangy @ BlackGhost ~] $ Uniq -- help usage: uniq [Option]... [file] Filters adjacent matching rows from the input file or standard input and writes them to the output file or standard output. If no option is attached, the matching row is merged at the first appearance. Parameters required for long options are also required for short options. -C, -- count // Add the prefix number-d, -- repeated, indicating the number of occurrences of the corresponding row in front of each row. // only duplicate rows-D are output, -- all-repeated // only outputs duplicate rows, but several rows output the number of-f, -- skip-fields = N //-f ignored segments, -f 1 ignores the first section-I, -- ignore-case // case insensitive-s, -- skip-chars = N // The root-f is a bit like, however,-s is ignored. When-s 5 is followed, the next five characters www.2cto.com-u, -- unique // are ignored and all repeated characters are displayed, the distinct function of the root mysql is somewhat like-z, -- zero-terminated end lines with 0 byte, not newline-w, -- check-chars = N // do not compare the content after the nth character in each line -- help // display the help information and exit -- version // display the version information and exit it -z doesn't know how to use it.
3, test the text file uniqtestthis is a test this is a test I am tank I love tank this is a test whom have a try WhoM have a try you have a try I want to abroad those are good men we are good men
IV, instance details [zhangy @ BlackGhost mytest] $ uniq-c uniqtest 3 this is a test 1 I am tank www.2cto.com 2 I love tank 1 this is a test // It is repeated with the first line 1 whom have a try 1 WhoM have a try 1 you have a try 1 I want to abroad 1 those are good men 1 we are good men
As shown in the preceding example, uniq only checks adjacent rows when checking duplicate rows. Duplicate data, many of which are not adjacent together. [Zhangy @ BlackGhost mytest] $ sort uniqtest | uniq-c 1 WhoM have a try 1 I am tank 2 I love tank 1 I want to abroad 4 this is a test 1 those are good men 1 we are good men 1 whom have a try 1 you have a try can solve the problem mentioned in the previous example [zhangy @ BlackGhost mytest] $ uniq-d-c uniqtest 3 this is a test www.2cto.com 2 I love tank uniq-d only show duplicate rows [zhangy @ BlackGhost mytest] $ uniq-D uniqtest this is a test this is a te St this is a test I love tank uniq-D: only duplicate rows are displayed, and several duplicate rows are displayed. He cannot use [zhangy @ BlackGhost mytest] $ uniq-f 1-c uniqtest 3 this is a test 1 I am tank 2 I love tank 1 this is a test 2 whom have a try 1 you have a try 1 I want to abroad 2 those are good men // only one row, the two rows are displayed. Here, those only has one row, but the rows are repeated. This is because-f 1 ignores the first column and checks that the repeat starts from the second field. [Zhangy @ BlackGhost mytest] $ uniq-I-c uniqtest 3 this is a test www.2cto.com 1 I am tank 2 I love tank 1 this is a test 2 whom have a try // capital, one lower case 1 you have a try 1 I want to abroad 1 those are good men 1 we are good men
During the check, case Insensitive [zhangy @ BlackGhost mytest] $ uniq-s 4-c uniqtest 3 this is a test www.2cto.com 1 I am tank 2 I love tank 1 this is a test 3 whom have try // What is the difference between the previous example 1 I want to abroad 1 those are good men 1 we are good men
During the check, do not consider the first four characters, so that whom have a try is the same as you have a try. [Zhangy @ BlackGhost mytest] $ uniq-u uniqtest I am tank this is a test whom have a try WhoM have a try you have a try I want to abroad those are good men we are good men
Repeated items, then all of them are displayed. [zhangy @ BlackGhost mytest] $ uniq-w 2-c uniqtest 3 this is a test www.2cto.com 3 I am tank 1 this is a test 1 whom have a try 1 WhoM have a try 1 you have a try 1 I want to abroad 1 those are good men 1 we are good men do not check content after 2nd characters in each line, so I am tank root I love tank is the same. From the bottom-sea cangying (tank) blog

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.