Text Sorter

Sort lines alphabetically or numerically in either direction.

  • Runs locally in your browser
  • No upload required

Try it

One item per line; processed entirely in your browser.

Result
apple banana cherry
Lines
3
Unique removed
0
apple
banana
cherry

Supported formats

Input
text, select, boolean
Output
text

Privacy

Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.

Processing
In your browser
Privacy level
Browser only

Sorted 3 line(s) ascending.

How it works

  • Normalised CRLF and lone CR line endings to LF.
  • Kept every line.
  • Compared lines as text.
  • Folded case before comparing.
  • Ordered the lines ascending by Unicode code point, keeping input order for ties.
  • The comparison is locale-independent so the output is deterministic.
  • Sorting already-sorted output changes nothing (idempotent).

Methodology

  1. Normalise CRLF and lone CR to LF and split into lines.
  2. Optionally remove duplicate lines first, keeping the first occurrence.
  3. Compare by a leading number when numeric mode is on and both lines have one, otherwise by Unicode code point.
  4. Fold case first when the comparison is case-insensitive.
  5. Reverse the comparison for descending order while keeping input order for ties.

Usage

  1. Paste the list, one item per line.
  2. Choose the direction and comparison options.
  3. Run the tool and copy the sorted text.

Examples

These are examples, not current values: they use fixed inputs, while the interactive tool computes live results in your browser.

Alphabetical ascending

jsonSelect to copy
{
  "text": "banana\napple\ncherry",
  "direction": "asc",
  "caseSensitive": false,
  "numeric": false,
  "unique": false
}

Numeric descending

jsonSelect to copy
{
  "text": "10\n2\n1",
  "direction": "desc",
  "caseSensitive": false,
  "numeric": true,
  "unique": false
}

Unique sorted

jsonSelect to copy
{
  "text": "b\na\nb",
  "direction": "asc",
  "caseSensitive": true,
  "numeric": false,
  "unique": true
}

Limitations

Deterministic sorting

Sorting that depends on the visitor's locale can produce different output on different machines. This tool uses code-point order so the same input always yields the same sorted list.

Frequently asked questions

Which order does the text comparison use?
Unicode code-point order, which is stable across machines and locales. It is not a language-aware dictionary order.
How does numeric mode treat mixed lists?
When both lines start with a number they compare numerically; lines without a leading number are placed after the numbered lines and compared as text.

Sources

  1. ECMA-262: ECMAScript Language Specification — Array.prototype.sort — Ecma International
  2. MDN Web Docs — Array.prototype.sort() — Mozilla