Advanced usage of the Linux sort sort command

Source: Internet
Author: User

In Linux, it is easy to sort by rows by using sort.
But sometimes life always throws you a question. If you use sort to sort by multiple column values, tab is used as a delimiter, and some columns need to be sorted in reverse order, the sort command is slightly frustrating to implement.

Let's look at concrete examples.
For example, the following file content, using [TAB] to split:

Name    score   totaluser1   1       4user2   2       3user3   3       2user4   4       1

Sort 2 and 3 fields, 2 fields descending, 3 characters orderby order

Sort -T $'t' K 2r,2 -K 3n,3 user.txt

The explanations are as follows:
-T $ ' t ': Specify Tab as delimiter
-K 1, 1: Sort by the value of the first column, if there is only one 1, it is equivalent to telling sort to start directly to the end of the line from the first column
N: Represents a numeric order, by default the city dictionary order, such as 10<2
R:reverse in reverse order, the city is ordered by default

Advanced usage of the Linux sort 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.