sort sort
Считывает ввод, сортирует данные и записывает результаты на экран, в файл или на другое устройство. Reads input, sorts data, and writes the results to the screen, to a file, or to another device.
Синтаксис Syntax
Параметры Parameters
Параметр Parameter | Описание Description |
---|---|
/r /r | Меняет порядок сортировки на обратный (т. е. Сортировка от Z к A и от 9 до 0). Reverses the sort order (that is, sorts from Z to A and from 9 to 0). |
/+ | Указывает номер позиции символа, где Сортировка будет начинать каждое сравнение. Specifies the character position number where sort will begin each comparison. N может быть любым допустимым целым числом. N can be any valid integer. |
/m /m | Указывает объем основной памяти, используемый для сортировки в килобайтах (КБ). Specifies the amount of main memory to use for the sort in kilobytes (KB). |
/l /l | Переопределяет порядок сортировки символов, определенных локальом системы по умолчанию (то есть языка и страны или региона, выбранных во время установки). Overrides the sort order of characters that are defined by the system default locale (that is, the language and Country/Region selected during installation). |
/рек /rec | Указывает максимальное число символов в записи или строку входного файла (значение по умолчанию — 4 096, а максимальное — 65 535). Specifies the maximum number of characters in a record or a line of the input file (the default value is 4,096 and the maximum is 65,535). |
[ :][ |
]
]
]
Комментарии Remarks
По умолчанию сравнения начинаются с первого символа каждой строки. By default, comparisons start at the first character of each line. /+ Параметр командной строки начинает сравнение по символу, указанному параметром N. Например, /+3 указывает, что каждое сравнение должно начинаться с третьего символа каждой строки. The /+ command-line option starts comparisons at the character that is specified by N. For example, /+3 indicates that each comparison should begin at the third character of each line. Строки, содержащие менее N символов, сортируются перед другими строками. Lines with fewer than N characters collate before other lines.
Используемая память всегда составляет не менее 160 КБ. The memory used is always a minimum of 160 KB. Если размер памяти указан, то для сортировки используется точный указанный объем (по крайней мере 160 КБ), независимо от объема доступной основной памяти. If the memory size is specified, the exact specified amount is used for the sort (must be at least 160 KB), regardless of how much main memory is available.
Максимальный размер памяти по умолчанию, если размер не указан, составляет 90% доступной основной памяти, если входные и выходные данные являются файлами, или 45% основной памяти в противном случае. The default maximum memory size when no size is specified is 90% of the available main memory, if both the input and output are files, or 45% of main memory otherwise. Значение по умолчанию обычно обеспечивает наилучшую производительность. The default setting usually gives the best performance.
В настоящее время единственным альтернативом языкового стандарта по умолчанию является язык C, который быстрее, чем сортировка на естественном языке (Сортирует символы в соответствии с их двоичными кодировками). Currently, the only alternative to the default locale is the C locale, which is faster than natural language sorting (it sorts characters according to their binary encodings).
Символ вертикальной черты () можно использовать | для направления входных данных в команду Sort из другой команды или для направления отсортированного вывода в другую команду. You can use the pipe symbol ( | ) to direct input data to the sort command from another command or to direct sorted output to another command. Входные и выходные файлы можно указать с помощью символов перенаправления ( или > ). You can specify input and output files by using redirection symbols ( or > ). Он может быть быстрее и эффективнее (особенно с большими файлами) для непосредственного указания входного файла (как определено в параметре имя_файла1 в синтаксисе команды), а затем указать выходной файл с помощью параметра /o . It can be faster and more efficient (especially with large files) to specify the input file directly (as defined by filename1 in the command syntax), and then specify the output file using the /o parameter.
Команда Sort не различает прописные и строчные буквы и не имеет ограничений на размер файла. The sort command doesn’t distinguish between uppercase and lowercase letters and has no limit on file size.
Программа сортировки использует таблицу упорядочения, соответствующую коду страны или региона и параметрам кодовой страницы. The sort program uses the collating-sequence table that corresponds to the Country/Region code and code-page settings. Символы, превышающие код ASCII 127, сортируются на основе сведений в файле Country.sys или в альтернативном файле, указанном в команде Country в файле config. NT. Characters greater than ASCII code 127 are sorted based on information in the Country.sys file or in an alternate file specified by the country command in your Config.nt file.
Если сортировка соответствует максимальному размеру памяти (по умолчанию или в соответствии с параметром /m ), то сортировка выполняется в рамках одного прохода. If the sort fits within the maximum memory size (as set by default or as specified by the /m parameter), the sort is performed in a single pass. В противном случае сортировка выполняется в двух отдельных проходах сортировки и слияния, а объем памяти, используемый для обоих проходов, равен. Otherwise, the sort is performed in two separate sort and merge passes, and the amounts of memory used for both passes are equal. При выполнении двух проходов частично отсортированные данные сохраняются во временном файле на диске. When two passes are performed, the partially sorted data is stored in a temporary file on disk. Если недостаточно памяти для выполнения сортировки в два прохода, выдается ошибка времени выполнения. If there is not enough memory to perform the sort in two passes, a run-time error is issued. Если параметр командной строки /m используется для указания большего объема памяти, чем доступно на самом деле, может произойти снижение производительности или ошибка времени выполнения. If the /m command-line option is used to specify more memory than is truly available, performance degradation or a run-time error can occur.
Примеры Examples
Для сортировки и вывода в обратную сортировку строк в файле с именем expenses.txt введите: To sort and display, in reverse order, the lines in a file named expenses.txt, type:
Чтобы выполнить поиск в большом файле с именем maillist.txt для текстового Jones и отсортировать результаты поиска с помощью канала (), | чтобы направить выходные данные команды Find в команду Sort , введите: To search a large file named maillist.txt for the text Jones, and to sort the results of the search using the pipe ( | ) to direct the output of a find command to the sort command, type:
Команда создает отсортированный список строк, содержащих указанный текст. The command produces a sorted list of lines that contain the specified text.
Чтобы отсортировать ввод с клавиатуры и отобразить результаты на экране по алфавиту, можно сначала использовать команду Sort без параметров, введя: To sort keyboard input and display the results alphabetically on the screen, you can first use the sort command with no parameters, by typing:
Затем введите текст, который нужно сортировать, и нажмите клавишу ВВОД в конце каждой строки. Then type the text that you want sorted, and press ENTER at the end of each line. Завершив ввод текста, нажмите клавиши CTRL + Z, а затем нажмите клавишу ВВОД. When you have finished typing text, press CTRL+Z, and then press ENTER. Команда Sort отображает введенный текст, отсортированный в алфавитном порядке. The sort command displays the text you typed, sorted alphabetically.
Windows sort by name
Reads input, sorts data, and writes the results to the screen, to a file, or to another device.
Syntax
Parameters
Parameter | Description |
---|---|
/r | Reverses the sort order (that is, sorts from Z to A and from 9 to 0). |
/+ | Specifies the character position number where sort will begin each comparison. N can be any valid integer. |
/m | Specifies the amount of main memory to use for the sort in kilobytes (KB). |
/l | Overrides the sort order of characters that are defined by the system default locale (that is, the language and Country/Region selected during installation). |
/rec | Specifies the maximum number of characters in a record or a line of the input file (the default value is 4,096 and the maximum is 65,535). |
[ :][ |
]
]
]
Remarks
By default, comparisons start at the first character of each line. The /+ command-line option starts comparisons at the character that is specified by N. For example, /+3 indicates that each comparison should begin at the third character of each line. Lines with fewer than N characters collate before other lines.
The memory used is always a minimum of 160 KB. If the memory size is specified, the exact specified amount is used for the sort (must be at least 160 KB), regardless of how much main memory is available.
The default maximum memory size when no size is specified is 90% of the available main memory, if both the input and output are files, or 45% of main memory otherwise. The default setting usually gives the best performance.
Currently, the only alternative to the default locale is the C locale, which is faster than natural language sorting (it sorts characters according to their binary encodings).
You can use the pipe symbol ( | ) to direct input data to the sort command from another command or to direct sorted output to another command. You can specify input and output files by using redirection symbols ( or > ). It can be faster and more efficient (especially with large files) to specify the input file directly (as defined by filename1 in the command syntax), and then specify the output file using the /o parameter.
The sort command doesn’t distinguish between uppercase and lowercase letters and has no limit on file size.
The sort program uses the collating-sequence table that corresponds to the Country/Region code and code-page settings. Characters greater than ASCII code 127 are sorted based on information in the Country.sys file or in an alternate file specified by the country command in your Config.nt file.
If the sort fits within the maximum memory size (as set by default or as specified by the /m parameter), the sort is performed in a single pass. Otherwise, the sort is performed in two separate sort and merge passes, and the amounts of memory used for both passes are equal. When two passes are performed, the partially sorted data is stored in a temporary file on disk. If there is not enough memory to perform the sort in two passes, a run-time error is issued. If the /m command-line option is used to specify more memory than is truly available, performance degradation or a run-time error can occur.
Examples
To sort and display, in reverse order, the lines in a file named expenses.txt, type:
To search a large file named maillist.txt for the text Jones, and to sort the results of the search using the pipe ( | ) to direct the output of a find command to the sort command, type:
The command produces a sorted list of lines that contain the specified text.
To sort keyboard input and display the results alphabetically on the screen, you can first use the sort command with no parameters, by typing:
Then type the text that you want sorted, and press ENTER at the end of each line. When you have finished typing text, press CTRL+Z, and then press ENTER. The sort command displays the text you typed, sorted alphabetically.