Use of linux sort commands-general Linux technology-Linux programming and kernel information. The following is a detailed description. This day, I accidentally used the sort-f command to find a strange problem with sort. Sort-f is described in man as "fold lower case to upper case characters", that is, case-insensitive sorting. However, using sort directly is also the result.
Then I finally found out the problem. LC_ALL has an impact on sort results. Previously, LC_ALL was set to zh_CN.GB18030. (Use the locale command to view details)
After info sort is verified, the standard is set to LC_ALL = C, and then the result is the standard sort sorting.
Input:
Export LC_ALL = C
Run the sort command and sort-F to check the result.
In addition, locale also has an impact on some display results. For example, the display results of time in ll are different in Chinese and English. There will be one fewer column in Chinese when the date was last year. As shown below:
-Rw-r -- 1 root 571 Dec 25 2006 reactivate_account.php
-Rw-r -- 1 root 0 03-03 16:28 test
Common sort commands:
Sort-t:-k3-n/etc/passwd
Note: This command is used to sort the 3rd columns and UIDs of passwd.
Parameters:
-T indicates the delimiter, separated by:. By default, it is separated by spaces.
-K is used to sort data by a column. Here, the data is sorted by 3rd columns. The default value is 1st columns (starting from 1 ).
-N is sorted by number. If the-n parameter is not added, the sorting result starts with the number on the leftmost side, which is equivalent to a letter comparison method.
-K can be added when more columns are required.
Sort-t:-k3-k4-n/etc/passwd
Sort by 3rd columns first, and then by 4th columns.
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