Uniq Command Summary

Source: Internet
Author: User

Uniq: Finds a single row from a given input (stdin or command-line parameter file) by eliminating duplicate content. It is also possible for the user to identify duplicate rows that appear in the input. Uniq can only be used for sequential data entry, so Uniq either uses a pipeline or takes a sorted file as input and is always used in combination with the sort command.


[[Email protected] ~]# man uniquniq (1)                             user commands                          uniq (1) name        uniq - report or omit repeated linesSYNOPSIS        uniq [OPTION]... [INPUT [OUTPUT]]DESCRIPTION        Filter  adjacent matching lines from INPUT  (or standard  Input), writing       to output  (or standard  Output).        with no options, matching lines are  merged to the&nbSp;first occurrence.       mandatory arguments to long  options are  mandatory  for  short  options        too.       -c, --count               prefix lines by the  number of occurrences       -d, --repeated               only print duplicate lines        -D, --all-repeated[=delimit-method]               print               all               duplicate              lines               delimit-method={none (default), Prepend, separate}  delimiting   is               done with blank lines.       - f, --skip-fields=n               avoid comparing the first n fields       -i,  --ignore-case              ignore  differences in case when comparing       -s, -- skip-chars=n              avoid  comparing the first n characters       -u, --unique               only print unique lines        -z, --zero-terminated               end lines with 0 byte, not newline        -w, --check-chars=N               compare no more than N characters in lines        --help display this help and exit        --version               output version information and exit        a field is a run of blanks  (Usually spaces and/or tabs), then non-blank        characters.  Fields are skipped before  chars.       note:  ' Uniq '  does not detect repeated  lines unless they  are  adjacent.        You  may want to sort the input first, or use  ' Sort -u '  without  ' Uniq ' .       also, comparisons  honor the rules specified by  ' Lc_collate '.

1,-C parameters: Count the number of occurrences of the line, and put the number of times at the beginning.

[[email protected] ~]# cat test.txt testliyaooldboytestjustoldboytest[[email protected] ~]# uniq-c test.txt 1 Test      1 Liyao 1 Oldboy 1 Test 1 just 1 Oldboy 1 test[[email protected] ~]# sort test.txt|uniq-c 1 just 1 Liyao 2 Oldboy 3 test[[email protected] ~]#

By contrast, you can see that there are no sorted inputs, only the prefix numbers are displayed in front of each line.


2,-D parameter: Only duplicate rows are displayed.

[Email protected] ~]# sort test.txt |uniq-doldboytest[[email protected] ~]#

Similarly, for unordered input, Uniq does not reach the desired result.

[Email protected] ~]# uniq-d test.txt [[email protected] ~]#


3.-U parameter: Only a unique row is displayed.

[[email protected] ~]# uniq-u test.txt testliyaooldboytestjustoldboytest[[email protected] ~]# sort Test.txt |uniq-ujust Liyao[[email protected] ~]#


Uniq more commonly used parameters are mainly these three parameters, proficiency in these three parameters can be. Others, can be done to understand.

This article is from the "Yau Xin Zhai" blog, please be sure to keep this source http://mofei.blog.51cto.com/6840705/1760730

Uniq Command Summary

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.