With Sort by Pattern, you can sort selected lines using custom comparison rules.
In the CotEditor app
on your Mac, open a document.
Choose Text > Lines > Sort by Pattern.
Configure the sorting rules.
Click Sort.
Set how CotEditor extracts and compares sort keys for the selected lines.
Sample: You can test which part in a line is used for the sort comparison.
Sort key: Specify the part of each line to use for sorting.
Entire line: Compare entire lines.
Column: Treat lines as CSV (character-separated values) format and use the specific column for comparison. Whitespace around the separator is ignored.
| Option | Description |
|---|---|
| Delimiter | The character separating each column. You can use escape sequences such as |
| Position | The number of the column to use as the sort key. The column count starts at 1. |
Regular expression: Specify the part of each line to compare using regular expressions.
| Option | Description |
|---|---|
| Pattern | The regular expression pattern to extract the part to compare. |
| Ignore case | Whether to ignore character case when extracting the regular expression pattern. This option applies only to extracting the sort key. To perform a case-insensitive sort, use the “Ignore case” option in the sort options below. |
| Use captured group | The part in matches to use as the sort key. The entire match is used when this option is unselected. |
Sort options: Configure the behaviors on comparing sort keys.
| Option | Description |
|---|---|
| Ignore case | Ignore character case on sort. |
| Respect language rules | Fuzzily sort respecting the current language setting. For example, ignoring trivial differences such as character widths or diacritical marks. |
| Treat numbers as numeric values | Numbers within the sort keys are compared as numeric value. (for example, file12 > file5) |
| Keep the first line at the top | Exclude the first line from sorting. |
| In descending order | Sort results in descending order. |
Tip: The standard Sort command in the Text > Lines menu is equivalent to sorting by “Entire line” with the “Ignore case” and “Respect language rules” options enabled.