Unix/liunx sort

Source: Internet
Author: User

Unix/liunx sort explanation sort: Function Description: sorts text files. Syntax: sort [-bcdfimMnr] [-o <output file>] [-t <delimiter>] [+ <start column>-<End column>] [-- help] [-- verison] [file] supplementary instructions: sort sorts the content of a text file in the unit of action. Parameter: www.2cto.com-B ignores the leading space character in each line. -C: Check whether the files are sorted in order. -G is sorted by ordinary numbers. -D: When sorting, other characters are ignored except English letters, numbers, and spaces. -F: lowercase letters are considered as uppercase letters. -In I sorting, except for ASCII characters between 176 and, other characters are ignored. -K is sorted by a column. For details, see below. -M combines several sorted files. -M sorts the first three letters by the abbreviation of the month. -N is sorted by the value size. -S: stable sorting. This option is important if there is a requirement on the input order. -S limits the memory used for sorting. Unit: M \ G \ T \ B \ E \ Z \ Y-o <output file> Save the sorted result to the specified file. -R is sorted in reverse order. -T <delimiter> specifies the column delimiter used for sorting. -U removes duplicate rows. -Help: displays help. -Version: displays the version information. By default, sort separates fields with spaces and tabs by default, and performs lexicographically ascending sorting of the first field. If no input file is specified, data is obtained from the standard input.
Note that the sort option is not particularly worth mentioning. The syntax format of the-k option is as follows: [FStart [. CStart] [Modifier] [, [FEnd [. CEnd] [Modifier] the syntax format can be divided into two parts: Start and End. If the End part is not set, End is considered to be the End of the row. The Start part is also composed of three parts. The Modifier part is the option part similar to n and r we mentioned earlier. Let's focus on FStart and C. Start in Start. C. Start can also be omitted. If it is omitted, it indicates starting from the beginning of the local domain. In the previous example,-k 2 and-k 3 are examples that omit C. Start. FStart. CStart, where FStart indicates the domain used, and CStart indicates that the FStart field starts from the first character of the FStart field ". Similarly, in the End section, you can set FEnd. CEnd. If you omit. CEnd, it indicates the End to the End of the domain, that is, the last character of the local domain. Or, if you set CEnd to 0 (zero), it also indicates the end to the end of the "domain ". Options available in the modifier section: B, d, f, I, n, or r. Www.2cto.com where n and r are already familiar to you. B indicates that the blank sign-in characters in the current domain are ignored. D indicates that the domain is ordered alphabetically (that is, only blank spaces and letters are considered ). F indicates that the domain is case-insensitive for sorting. I indicates ignore "printable characters" and only sort printable characters. (Some ASCII characters cannot be printed. For example, \ a is an alarm, \ B is a backspace, \ n is a line feed, and \ r is a carriage return) in addition, sometimes the symbols + 1-2 are displayed after the sort command. What is this? Ignore it. This is not introduced in the manual anymore. It is a very old usage. Example: sort by the second letter of the first key column: $ sort-k 1.2 file.txt sort by the second letter of the first key column, if the second letter is the same, it is sorted in descending order according to the numerical value in the third column. $ Sort-k 1.2, 1.2-k 3, 3nr file.txt by runming918

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.