# Sort lines using specific pattern in CotEditor on Mac

From Sort by Pattern command in the Text > Lines menu, you can sort selected lines by specifying the way to compare.

The normal Sort command in the Text > Lines menu is the same as sorting “Entire line” with “Ignore case” and “Respect language rules” options on.

## Sample

In this field, you can test which part in a line will be used for sort comparison.

## Sort key

Specify the part in lines to compare on sort.

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 just ignored.

  Option | Description
  --- | ---
  Delimiter | The character separating each column. You can use escape sequences such as `\t` for the tabular character. A comma is used when this field is blank.

Position The number of the column to use as the sort key. The column count starts at 1.
Regular expression
  Specify the part to compare with the regular expression.

  Option | Description
  --- | ---
  Pattern | The regular expression pattern to extract the part to compare.

Ignore case Whether ignore the character case by extracting the regular expression pattern. This option is used only for the sort key extraction. To set case-insensitive state for the sort phase, set in the sort option bellow.
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

Options to control behavior 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 value | Numbers within the sort keys are compared as numeric value. (e.g., file12 > file5)
Keep the first line at the top | Ignore the first line by sorting.
In descending order | Sort results in descending order.

## See also

- Use the regular expression