This command allows you to set the sort options and perform a sort of the active file or all open files. When the sort is executed, a pair of lines are compared as follows: sort compares each pair of fields, in the order specified, according to the associated ordering options, until a difference is found or no fields are left. If no key fields are specified, sort uses a default key of the entire line. Finally, as a last resort when all keys compare equal, sort compares entire lines as if no ordering options other than Reverse Order were specified.
The sort process has no limit on input line length or restrictions on bytes allowed within lines. In addition, if the final byte of an input file is not a newline, the sort silently supplies one. A line's trailing newline is not part of the line for comparison purposes.
When the Advanced Sort Options command is selected, a dialog is presented with the following options:
Using this dropdown users may configure the sort to affect either the Current Document or All Open Documents.
Output to New File
If this option is selected, the sort results will be written to a new file and the original source file will not be affected by the sort.
Merge Sort Results
This option is only active if All Open Documents is selected in the Sort dropdown. When selected, this causes all open documents to be sorted and merged into a single result file.
Using this dropdown, users may specify the sort method used to sort the active file(s). The following options affect the ordering of output lines. They may be specified globally or as part of a specific key field. If no key fields are specified, global options apply to comparison of entire lines; otherwise the global options are inherited by key fields that do not specify any special options of their own. The following options are available:
|Sort in phone directory order: ignore all characters except letters, digits and blanks when sorting. By default letters and digits are those of ASCII and a blank is a space or a tab, but the option selected using the Locale dropdown can change this.|
|Sort numerically. The number begins each line and consists of optional blanks, an optional '-' sign, and zero or more digits possibly separated by thousands separators, optionally followed by a decimal-point character and zero or more digits. An empty number is treated as '0'. The Locale dropdown specifies the decimal-point character and thousands separator. By default a blank is a space or a tab, but the Locale dropdown can change this.|
|Month||An initial string, consisting of any amount of blanks, followed by a month name abbreviation, is folded to UPPER case and compared in the order 'JAN' < 'FEB' < ... < 'DEC'. Invalid names compare low to valid names. The Locale dropdown determines the month spellings. By default a blank is a space or a tab, but the Locale dropdown can change this.|
Sort by version name and number. It behaves like a standard sort, except that each sequence of decimal digits is treated numerically as an index/version number. See details about Version sorting below.
Sort by hashing the input keys and then sorting the hash values. Choose the hash function at random, ensuring that it is free of collisions so that differing keys have differing hash values. This is like a random permutation of the inputs, except that keys with the same value sort together. If multiple random sort fields are specified, the same random hash function is used for all fields. To use different random hash functions for different fields, you can invoke sort more than once.
Sort lexicographically. Every character in the line being sorted (or the specified key) is sorted in alphabetic order like a dictionary.
Details about the Version sort method
Version sorting handles the fact that file names frequently include indices or version numbers. Standard sorting usually does not produce the order that one expects because comparisons are made on a character-by-character basis. Version sorting is especially useful when browsing directories that contain many files with indices/version numbers in their names:
$ ls -1 $ ls -1v
Version-sorted strings are compared such that if ver1 and ver2 are version numbers and prefix and suffix (suffix matching the regular expression '(.[A-Za-z~][A-Za-z0-9~]*)*') are strings then ver1 < ver2 implies that the name composed of “prefix ver1 suffix” sorts before “prefix ver2 suffix”.
Note also that leading zeros of numeric parts are ignored:
$ ls -1 $ ls -1v
Some suffixes will not be matched by the regular expression mentioned above. Consequently these examples may not sort as you expect:
|Remove Duplicates||If this option is selected, lines detected as duplicates will be removed from the result.|
|Reverse Order||Reverse the result of comparison, so that lines with greater key values appear earlier in the output instead of later.|
|Ignore Leading Blanks||Ignore leading blanks when finding sort keys in each line. By default a blank is a space or a tab, but the Locale dropdown can change this. Note: blanks may be ignored by your locale's collating rules, but without this option they will be significant for character positions specified in Keys.|
|Locale||This dropdown allows the user to specify the locale to be used for the sorting operation. This setting can affect the result of Dictionary, Month, Numeric, and Version sorts.|
|Ignore Case||Fold lowercase characters into the equivalent uppercase characters when comparing so that, for example, 'b' and 'B' sort as equal. The Locale dropdown determines character types.|
|Stable Sort||Make sort stable by disabling its last-resort comparison so that lines in which all fields compare equal are left in their original relative order. This option has no effect if no fields or global ordering options other than Reverse Order are specified.|
By default sort detects the transition from non-blank characters to blanks (by default, spaces or tabs). This is used to determine the beginning and end of sort fields. If desired, the user may specify a specific character to be recognized as a field delimiter.
Use Entire Line as Key
If this option is selected, the entire line will be evaluated when sorting the file. Individual fields/characters are not used with this option.
If preferred, the user may specify keys which determine sorting methods and sorting order. Unless otherwise specified, sorting keys will inherit the global sort options for Ignore Case and Ignore Blanks.
Sorting Keys are defined by specifying the following items: Start Field, Start Char., End Field, End Char. Fields and character positions are numbered starting with 1; a character position of zero for End Char. indicates the field's last character. If field values are specified but the start and end character values are not, the sort key will default to the beginning and end of the specified field(s). Keys can span multiple fields.
The options Ignore Case, Ignore Blanks, and the sorting method selected are specific to the relevant key. If these options are not specified but the key fields and characters are specified, the specified keys will be sorted using the options specified globally.
Pressing the Sort button begins the sorting process using the specified parameters. Depending on the size of the file being sorted, you may notice a prompt indicating that the file is locked for sorting. While the file is being sorted, it is locked and may not be modified.
Article Number: 2231
Posted: Wed, Nov 16, 2011 1:36 PM
Last Updated: Fri, Nov 18, 2011 10:19 AM
Online URL: http://www.ultraedit.com/help/article/advanced-sort-options-2231.html