"Pick" Sort command

Source: Internet
Author: User

Options

-B: Ignores whitespace characters that begin before each line;

-C: Check whether the file has been sorted in order;

-D: When sorting, ignore other characters while processing English letters, numbers and space characters;

-F: When sorting, lowercase letters are treated as uppercase letters;

-I: When sorting, omit other characters except ASCII characters between 040 and 176;

-M: Merge the files of several sort numbers;

-M: Sorts the first 3 letters according to the abbreviation of the month;

-N: According to the size of the numerical order;

-o< output file;: Deposit the sorted result into the prepared document;

-r: Sort in reverse order;

-t< delimited character;: Specifies the field separator character to use when sorting;

-U: Removes duplicate rows in the output line;

+< start >-< end fields: Sort by the specified fields, ranging from the Start field to the previous column in the End field.

From Http://man.linuxde.net/sort

1 How the Sort works

Sort compares each line of a file as a unit, comparing it from the first character backwards, to the ASCII value in turn, and finally outputting them in ascending order.

Cat seq  sortseq. Txtapplebananaorangepear

The-t option and the-K option for 2.sort

Cat Facebook.txtbanana: :5.5Apple:2.5pear:2.3  Orange:3.4

This file has three columns, separated by a colon between the column and column, the first column indicates the fruit type, the second column represents the fruit quantity, and the third column represents the fruit price. So I would like to sort by the number of fruits, that is, in the second column, how to use the sort implementation? Fortunately, sort provides the-t option, after which you can set the spacer. (does not think of cut and paste's-D option, resonance ~ ~) after specifying the spacer, you can use-K to specify the number of columns.

Sort 2 -t:facebook.txtapple::2.5Orange:3.4  Banana:5.5pear:2.3

We use the colon as the spacer, and we sort the numbers in ascending order for the second column, and the result is very satisfying.

3. The-N option for sort

Have you ever encountered 10:2 small cases. I've met anyway. This occurs because the sorting program sorts the numbers by character, and the sorting program compares 1 and 2, which is obviously 1 small, so 10 is placed before 2. This is also the sort's consistent style. If we want to change this situation, we need to use the-n option to tell sort, "Sort by value"!

"Pick" Sort command

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.