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