English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The Linux 'sort' command is used to sort the content of text files.
The 'sort' command can sort the content of text files line by line.
sort [-bcdfimMnr][-o<Output File>][-t<Separator Character>][+<Starting Position>-<End Field>][--help][--verison][File]
Parameter Description:
-Ignore the leading spaces at the beginning of each line.
-Check if the file has been sorted in order.
-d When sorting, handle English letters, numbers, and spaces, and ignore other characters.
-f When sorting, treat lowercase letters as uppercase letters.
-i When sorting, except for 040 to176The ASCII characters between, ignore other characters.
-m Merge several sorted files.
-M Before3Letters are sorted according to the abbreviation of the month.
-n Sort according to the size of the number.
-u Means unique (unique), the output result is after removing duplicates.
-o<Output File> Store the sorted results in the specified file.
-r Sort in reverse order.
-t<Separator Character> Specify the field separator character used for sorting.
+<Starting Position>-<End Position> Sort by the specified field, the range is from the starting field to the previous field before the ending field.
--help Show help.
--version Show version information.
The command used to sort the lines of the file in the default way using the sort command is as follows:
sort testfile
The sort command will sort the first column of the text file in the order of ASCII code by default and output the results to standard output.
The original sorting of the testfile file can be known by using the cat command as follows:
$ cat testfile #Original sorting of testfile file test 30 Hello 95 Linux 85
The results after sorting with the sort command are as follows:
$ sort testfile #Reorder the results Hello 95 Linux 85 test 30