Several methods of shell script de-weight

Source: Internet
Author: User

    • Test file
cat >testjasonjasonjasonfffff

Press CTR + D to save

1, Sort-u

sort -u testfffffjason

2, Uniq

Uniq Testjasonfffffjason

This shows that Uniq needs to be sorted before it can be re-

3, sort, pipe and uniq combined use

    • Remove duplicates and keep a duplicate of the data
Sort test| Uniq Fffffjason
    • Remove all duplicate rows (do not keep duplicate rows), and calculate the number of rows
Sort test| uniq -UC      1 fffff
    • Find all duplicate rows and calculate the number of rows
Sort test| uniq -DC      4 Jason
    • According to a field to weight

Change the original data to

 more 1 2 12 3
Sort 1,1 -21

Man sort view the use of sort, as described by the-K parameter:

-K,--key=pos1[,pos2]
Start a key at POS1 (Origin 1), end it at POS2 (default end of line)

That is,-K which columns are sorted, POS1 is the start column, Pos2 is the end column

Several methods of shell script de-weight

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.