The use of sort in Linux

Source: Internet
Author: User
Tags sorts

Sort function: Sorts the contents of a file line by row, if the first letter of the two lines is the same, continues to compare the next character of the two lines, and so on

Syntax: sort [Options] File

Sort sorting is the inverse of all the rows in the specified file and displays the results on standard output, such as not specifying an input file or using "-", which means that the sorted content is from the standard input


Sort sorting is done based on the comparison of one or more key words drawn from the input row, the smallest sequence of characters used to sort the sort keys, and by default, sorted in ASCII character order for the entire row


The options for changing the default settings are:

-M if the given file has been sequenced, merge the files.

-C Check whether the given file is ordered, if not, print error message, with a status value of 1 exit

-U leaves only one row for rows that are considered identical after sorting.

-O output file, writes the sort output to the output file instead of the standard output, if the output file is one of the input files, sort first writes the contents of the file to a temporary file, and then sorts and writes the output results


The options for changing the collation include:

-D is sorted in dictionary order, meaning the comparison of male letters, numbers, spaces, and tabs

-F Treats lowercase letters equal to uppercase

-I ignores nonprinting characters

-M as a month comparison: "JAN" < "FEB"

-R output sorting results in reverse order

+POSL-POS2 specifies one or more fields as the sort key, the field position starts from POS1, and until Pos2 (including POS1, excluding Pos2). If you do not specify POS2, the keyword is from pos1 to the end of the line. The position of the field and character starts at 0.

-B ignores leading blanks (spaces and tabs) when looking for keywords in each row.

-T separator Specifies the character separator as the field delimiter




This article is from the "Ride a Pig to Travel" blog, please be sure to keep this source http://songqinglong.blog.51cto.com/7591177/1706875

The use of sort in Linux

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.