sort
嚯嚯 发表于 2020-06-28 14:48浏览次数:
sort命令用于过滤输入,然后显示在计算机监视器上的结果或将其写入到文件中。
The sort command is used filter input and then display the results on a computer monitor or writes them to a file.
目录:
1 sort 运行系统环境
2 sort 语法
3 sort 示例
sort 运行系统环境
Windows 95
Windows 98
Windows xp
Windows vista
Windows 2000
Windows 7
Windows 8
Windows 10
Windows NT
Windows ME
All Versions of MS-DOS
sort 语法
Windows 2000,XP, 及更高版本的语法
SORT [/R] [/+n] [/M kilobytes] [/L locale] [/REC recordbytes] [[drive1:][path1]filename1] [/T
[drive2:][path2]] [/O [drive3:][path3]filename3]
/+n
|
指定字符号n,以开始每个比较。例如,/ + 3表示每次比较应从每行的第3个字符开始。少于n个字符的行将在其他行之前进行排序。默认情况下,比较从每行的第一个字符开始。
|
/L[OCALE] locale
|
用指定的语言环境覆盖系统默认语言环境。“ C”语言环境产生最快的整理顺序,并且是目前唯一的选择。排序始终不区分大小写。
|
/M[EMORY] kilobytes
|
指定用于排序的主内存量(以千字节为单位)。内存大小始终被限制为至少160 KB。如果指定了内存大小,则无论有多少主内存可用,都会使用精确的数量进行排序。
通常,不指定内存大小即可达到最佳性能。默认情况下,如果排序符合默认的最大内存大小,则排序将一次性完成(无临时文件)。否则,将分两次进行排序(将部分排序的数据存储在临时文件中),以便用于排序和合并的内存量相等。如果输入和输出均为文件,则默认的最大内存大小为可用主内存的90%,否则为主内存的45%。
|
/REC[ORD_MAXIMUM]
characters
|
指定记录中的最大字符数(默认4096,最大65535)。
|
/R[EVERSE]
|
颠倒排序顺序;也就是说,将Z排序为A,然后将9排序为0。
|
[drive1:][path1]filename1
|
指定要排序的文件。如果未指定,则对标准输入进行排序。指定输入文件比重定向与标准输入相同的文件要快。
|
/T[EMPORARY]
[drive2:][path2]
|
指定用于存放排序工作存储的目录路径,以防数据不适合主内存。默认为使用临时系统目录。
|
/O[UTPUT]
[drive3:][path3]filename3
|
指定存储排序后的输入的文件。如果未指定,则将数据写入标准输出。指定输出文件比将标准输出重定向到相同文件要快。
|
MS-DOS,Windows 95,98,ME, 和 NT 语法
对输入进行排序,并将结果写入屏幕,文件或其他设备。
SORT [/R] [/+n] [[drive1:][path1]filename1] [> [drive2:][path2]filename2] [command |] SORT [/R]
[/+n] [> [drive2:][path2]filename2]
/R
|
颠倒排序顺序;也就是说,将Z排序为A,然后将9排序为0。
|
/+n
|
根据第n列中的字符对文件进行排序。
|
[drive1:][path1]filename1
|
指定要排序的文件
|
[drive2:][path2]filename2
|
指定要存储排序后的输入的文件。
|
command
|
指定要对其输出进行排序的命令。
|
Windows 2000, XP, and later syntax
SORT [/R] [/+n] [/M kilobytes] [/L locale] [/REC recordbytes] [[drive1:][path1]filename1] [/T
[drive2:][path2]] [/O [drive3:][path3]filename3]
/+n
|
Specifies the character number, n, to begin each comparison. For example, /+3 indicates that each comparison should begin at the 3rd character in each line. Lines with fewer than n characters collate before other lines. Comparisons start at the first character in each line by default.
|
/L[OCALE] locale
|
Overrides the system default locale with the one specified. The "C" locale yields the fastest collating sequence and is currently the only alternative. The sort is always case insensitive.
|
/M[EMORY] kilobytes
|
Specifies the amount of main memory to use for the sort, in kilobytes. The memory size is always constrained to be a minimum of 160 kilobytes. If the memory size is specified the exact amount will be used for the sort, regardless of how much main memory is available.
The best performance is usually achieved by not specifying a memory size. By default, sort is done in one pass (no temporary file) if the sort fits in the default maximum memory size. Otherwise, the sort is done in two passes (with the partially sorted data being stored in a temporary file) such that the amounts of memory used for both the sort and merge passes are equal. The default maximum memory size is 90% of available main memory if both the input and output are files, and 45% of main memory otherwise.
|
/REC[ORD_MAXIMUM] characters
|
Specifies the maximum number of characters in a record (default 4096, maximum 65535).
|
/R[EVERSE]
|
Reverses the sort order; that is, sorts Z to A, then 9 to 0.
|
[drive1:][path1]filename1
|
Specifies the file to be sorted. If not specified, the standard input is sorted. Specifying the input file is faster than redirecting the same file as standard input.
|
/T[EMPORARY]
[drive2:][path2]
|
Specifies the path of the directory to hold
the sort's working storage, in case the data
does not fit in main memory. The default is
to use the temporary system directory.
|
/O[UTPUT]
[drive3:][path3]filename3
|
Specifies the file where the sorted input is to be stored. If not specified, the data is written to the standard output. Specifying the output file is faster than redirecting standard output to the same file.
|
MS-DOS, Windows 95, 98, ME, and NT syntax
Sorts input and writes results to the screen, a file, or another device.
SORT [/R] [/+n] [[drive1:][path1]filename1] [> [drive2:][path2]filename2] [command |] SORT [/R]
[/+n] [> [drive2:][path2]filename2]
/R
|
Reverses the sort order; that is, sorts Z to A, then 9 to 0.
|
/+n
|
Sorts the file according to characters in column n.
|
[drive1:][path1]filename1
|
Specifies file(s) to be sorted
|
[drive2:][path2]filename2
|
Specifies a file where the sorted input is to be stored.
|
command
|
Specifies a command whose output is to be sorted.
|
sort 示例
sort test.txt
此命令将显示test.txt中文本的排序结果。
sort test.txt /o output.txt
下一条命令将排序后的结果存储在output.txt文件中。
sort test.txt
This command would display the sorted results of the text in test.txt.
sort test.txt /o output.txt
This next command takes the sorted results and stores them in the output.txt file.
如果要对文件列表进行排序,则可以将dir命令与sort命令一起使用。例如,“ dir / on”对按字母顺序列出的文件进行排序。有关更多示例和选项,请参见dir命令页面。
If you want to sort the listing of the files, you can use the dir command with one of the sorting switches. For example, "dir /on" sorts the files listed in alphabetical order. See the dir command page for further examples and options.