the sort command is used to sort the contents of a text file
Sort can be sorted in the order of the text file content, in the unit of behavior.
Parameters:
-B: Ignores whitespace characters that begin before each line
-C: Check that the files are sorted in order
-D: When sorting, the letters, numbers, and whitespace characters are processed, ignoring other characters.
-F: Lowercase letters are treated as uppercase when sorting
-I: When sorting, in addition to ASCII characters between 040 and 176
-M: Merging several sorted files
-M: Sort the first three letters according to the abbreviation of the month
-N: Sort by numeric size
-o< output file;: Save sorted result in specified file
-r: Sort in reverse order
-t< split character;: Specifies the delimiter used when sorting
+< start >-< End fields > Sort by a specified field, from the Start field to the previous column in the End field
--help display Help.
Instance:
1. Sort files in ASCII order Test1
sort test1
2. Ignore file peers
sort -u test1或uniq test1
3.sort-n-r-k-T use
View a file First Sort.txt
cat sort.txtAAA:BB:CCaaa:30:1.6ccc:50:3.3ddd:20:4.2bbb:10:2.5eee:40:5.4eee:60:5.1
#将BB列按照数字从小到大顺序排列:
sort -nk 2 -t: sort.txtAAA:BB:CCbbb:10:2.5ddd:20:4.2aaa:30:1.6eee:40:5.4ccc:50:3.3eee:60:5.1
#将CC列数字从大到小顺序排列:
sort -nrk 3 -t: sort.txteee:40:5.4eee:60:5.1ddd:20:4.2ccc:50:3.3bbb:10:2.5aaa:30:1.6AAA:BB:CC
-N is sorted by numeric size,-R is in reverse order,-K is the field that specifies the sort of love you want,-t specifies that the field delimiter is a colon
The specific syntax format for the-K option:
The syntax format for the-K option:
FStart.CStart Modifie,FEnd.CEnd Modifier-------Start--------,-------End-------- FStart.CStart 选项 , FEnd.CEnd 选项
This syntax format can be separated into two parts, the start part and the end part. The start section is also made up of three parts, the modifier part of which is what we said earlier about the options section like N and R. We focus on the Fstart and C.start of the Start section. C.start can also be omitted, and the omitted words are indicated from the beginning of the domain. Fstart.cstart, where Fstart is the field that represents the use, and Cstart means "sort first character" from the first character in the Fstart field. Similarly, in the end section, you can set fend.cend, if you omit. Cend, the end to "domain Footer", which is the last character of the domain. Or, if you set Cend to 0 (0), it is also the end to "domain Footer".
1. Start with the second letter of the company's English name:
sort -t ‘ ‘ -k 1.2 book.txt ##以空格为分隔符baidu 100 5000sohu 100 4500google 110 5000guge 50 3000
Use K 1.2 to sort the string that begins the second character of the first field to the last character in the field. Sohu is the same as Google's second character, so follow the third character to the two characters who are the first to post a sort.
2. Sort the second letter of the company's English name only, if the same is sorted by the employee's salary in descending order:
sort -t ‘ ‘ -k 1.2,1.2 -nrk 3,3 book.txt
Because only 1.2 is sorted, so here's 1.2, and 1.2来 represents
The "Linux" base sort command