The----Sort command of the Linux command is used to sort the contents of the text file

Source: Internet
Author: User
Tags sorts

1. Sort Command function

The sort command is used to sort the contents of the text file, sorting the input rows by key-value fields and data type options, and by locale.

A predictable sequence of records makes it easier for users to see and use: The index, dictionary, directory, and phone book of the book, if no order is worthless, the sorted record is easier to program and more efficient.

2. Sort command syntax

Grammar

sort [Options] [File (s)]

Parameters:

    • -B ignores whitespace at the beginning
    • -c Check that the input is sorted correctly. Return exit code not 0 value if input is unordered
    • -D dictionary order: only literal numbers and blanks make sense
    • -G General Value: The field is compared as a floating-point number type.
    • -F treat Mixed letters as same case, case insensitive
    • -I ignores characters that cannot be printed
    • -K defines the sort key value field
    • -M merges several sorted files.
    • -M sorts the first 3 letters according to the abbreviation of the month.
    • -N Sorts by the size of the numbers.
    • -o< the output file > The sorted result into the specified file.
    • -R is sorted in reverse order.
    • -t< Delimited character > specifies the field separator character to use when sorting.
    • +< start >-< End fields > Sort by a specified field, ranging from the Start field to the previous column in the End field.
    • --help display Help.
    • --version Displays version information.

Sort reads the specified file and, if no file is given, reads the standard input and writes the sorted data to the standard output.

3. Sort case

1) Sort by field

(1) First field separated by a colon: Sort by user name

SORT-T:-k1,1/etc/passwd

(2) separated by a colon, first sorted by the fourth paragraph, then sorted in the third paragraph, displayed (counting from 1)

SORT-T:-k4n,-k3n/etc/passwd

2) Output The sorting results to the original file

Sort-r Test.txt-o Test.txt

3) Remove Duplicate rows

Sort-u Test.txt

The----Sort command of the Linux command is used to sort the contents of the text file

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.