sort Sort by numerical size

巴扎黑
巴扎黑Original
2017-08-22 14:07:189017browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn