6 Sort,uniq of the shell command

Source: Internet
Author: User

Sort is used for sorting, and the uniq is used to de-weigh, and these two commands are often used together. Mainly because the Uniq to the premise that the text must be arranged in order to be.

Of course, it is true that these two commands are indeed such functions. But they have other skills that are relevant. Come and see.

sort [option] filename ... Sorts the actions related to the file specified by filename.

option is commonly used to include:

-B ignores the front space.

-C Check to see if it is sorted and the result is through $?

-N Sort by number

-D dictionary sort.

-M Month sort

-H sort the units that people understand. For example 1K less than 1G

-R Reverse Reverse order

-R Random Randomly

-T Domain delimiter

-k keyword fields

-o output, default output to stdout, if this option is specified, output to a file.

-U removes duplicate rows after sorting.

The most common of these options is-b-n-t-k-R

Look at the effect:

1. Sort according to the size of the current catalog file:


The sort default delimiter is a Space and TAB key, so you don't need to specify it here.

2. Specify the output file.

This is the meaning of-o existence. You may want to redirect to the same file, but the result is that you will die badly. The data is lost. This is not the way.

3. Check if a file is lined up


4. Sorting to remove weight

Ok. Basically I'm using a few sort functions. Students in the actual application, should be accustomed to use man. Maybe English is not so good to understand, at least for me. But I have my own way, that is, I go to familiar with an order, and so on, I can understand the meaning of English.

By the fourth small example, it is easy to think of Uniq because it can also accomplish such intentions.

uniq [option] Input output Uniq accepts output and outputs the standard output of the result.

The common options are:

-D print out only duplicate rows

-U prints non-repeating rows only, opposite the-D effect

-C de-weighs and adds a count prefix.

-S N skips the first n characters.

-W N compares only the specified number of n characters, often combined with the S option, to specify a range for de-weight.


About these two commands summed up so much, or more to knock, even if there is no environment to use, create an environment to use.

6 Sort,uniq of the shell command

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.