sort Sort by numerical size

巴扎黑
Release: 2017-08-22 14:07:18
Original
8991 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!