Sort files in Linux

Source: Internet
Author: User
Sort files in Linux-general Linux technology-Linux programming and kernel information. For more information, see the following section. Contents of the file.txt file ======
Sanlu Erie 5
Erie Shengyuan 2
Sanlu Shengyuan 3
Sanlu Wahaha 1
Erie Wahaha 2
Shengyuan Wahaha 3
Sanlu Mengniu 2
Erie Mengniu 2
Wahaha Mengniu 4
Shengyuan Mengniu 5
==================================

Command: sort-r + 2 file.txt> file.txt _ sorted // sort by the third line. The-r parameter indicates that the sorting is in descending order. Otherwise, the sorting is in ascending order by default.

Arrange the following files:
======================================
Shengyuan Mengniu 5
Sanlu Erie 5
Wahaha Mengniu 4
Shengyuan Wahaha 3
Sanlu Shengyuan 3
Erie Mengniu 2
Erie Wahaha 2
Erie Shengyuan 2
Sanlu Mengniu 2
Sanlu Wahaha 1
======================================

Later: We found that things are not that simple. By default, numbers are sorted alphabetically. This problem was discovered only in later use because it was not checked in time. After several debugging, the-n parameter is added to the command to solve the problem.

Conclusion: after the program is completed, you must debug it in many ways to ensure that all possible problems have been fixed. The code that has not been tested is only a half product!
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.