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