Linux go first, sort, then uniq.

Source: Internet
Author: User

As you can see from the Help information in the Uniq command, this command filters only adjacent duplicate rows.

If you want to remove all duplicate rows, you need to sort them first, or use the Uniq-u

$Uniq--Husage:Uniq[OPTION] ... [INPUT [OUTPUT]] Filter adjacent matching lines from input (or standard INPUT), writing to output (or standard output). With no options, matching lines is merged to the first occurrence. Mandatory arguments toLongOptions are mandatory for  Shortoptions too. -C,--count prefix lines by the number of occurrences-D,--repeated only print duplicate lines, one forEach group-D Print all duplicate lines--all-repeated[=method] like-d, but allow separatinggroupsWith a empty line; METHOD={None (default), prepend,separate}-F,--skip-fields=N Avoid comparing the first n fields--group[=method] Show all items, separatinggroupsWith a empty line; METHOD={separate (default), Prepend,append,both}-I.,--ignore- CaseIgnore differencesinch  CaseWhen comparing-S,--skip-chars=N Avoid comparing the first n characters-U,--unique only print unique lines-Z,--zero-terminated line delimiter are NUL, not newline-W,--check-chars=n Compare No Morethan N charactersinchLines--Help display this help and exit--version output version information and Exita field is a run of blanks (usually spaces and/or TABs), Thennon-blankcharacters. Fields is skipped before chars.Note:  'uniq'  does not detect repeated lines unless they is adjacent. Want to  sort The input first, or use 'sort-u' without 'Uni Q'. Also, comparisons honor the rules specified by  'lc_collate'.

Cat tmp.txtaaaabbbbbb cc cc AA cc  catuniqaabbccaaccBB

Sort again uniq to remove all duplicates:

Cat Sort Uniq AABB cc

or use Uniq-u:

Cat uniq -UAAccBB

But this method does not necessarily work (see the example below)

$Head Info. Json-n20 | JQ. Industry |awk-F'"' '{print $}'|awk '{if (length > 0) print $}'|Uniq|Sort # ==> didn't go heavyBusiness Services Building decoration and other construction wholesale trade wholesale trade motor vehicles, electronic products and household products repair industry research and test development textile and apparel, apparel industry computer, communications and other electronic equipment manufacturing software and information technology services industry Road transport retail Trade $Head Info. Json-n20 | JQ. Industry |awk-F'"' '{print $}'|awk '{if (length > 0) print $}'|Uniq-u |Sort # ==> Go heavy not exactlyBusiness Services Building decoration and other construction industry wholesale trade motor vehicles, electronic products and household products repair industry research and test development textiles, apparel, apparel, computer, communications and other electronic equipment manufacturing software and information technology services industry Road transport retail Trade $Head Info. Json-n20 | JQ. Industry |awk-F'"' '{print $}'|awk '{if (length > 0) print $}'|Sort|Uniq # ==> to go back to successBusiness Services Building decoration and other construction industry wholesale business Research and testing of motor vehicles, electronic products and household products repair industry development of textiles, apparel, apparel, computer, communications and other electronic equipment manufacturing software and information technology Services Road transport retailing

Linux go first, sort, then uniq.

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.