Home >Operation and Maintenance >Linux Operation and Maintenance >sort Sort by numerical size
Generally, the default sort is sorted according to the ASCII of letters. Now I want to sort according to the size of numbers.
There is a file test here with the content:
1. 8723 23423
2. 321324 213432
3. 23 234
4. 123 231
5. 234 1234
6. 654 345234
Sort the first column
1. sort -n test
Sort the second column
1. sort -n -k 2 test
If you change the content of the test file to:
1. 8723,23423
2. 321324,213432
3. 23,234
4. 123,231
5. 234,1234
6. 654,345234
If you want to sort the second column by size
1. sort -n -t "," -k 2 test
If there is no -t option, it is the default space or tab key, so the -t option is not used above.
Use the -r option to sort in reverse order
The above is the detailed content of sort Sort by numerical size. For more information, please follow other related articles on the PHP Chinese website!