Text Sorter
Sort lines alphabetically or numerically in either direction.
- Runs locally in your browser
- No upload required
Try it
Supported formats
Privacy
Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.
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
- Normalise CRLF and lone CR to LF and split into lines.
- Optionally remove duplicate lines first, keeping the first occurrence.
- Compare by a leading number when numeric mode is on and both lines have one, otherwise by Unicode code point.
- Fold case first when the comparison is case-insensitive.
- Reverse the comparison for descending order while keeping input order for ties.
Usage
- Paste the list, one item per line.
- Choose the direction and comparison options.
- 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
{
"text": "banana\napple\ncherry",
"direction": "asc",
"caseSensitive": false,
"numeric": false,
"unique": false
}Numeric descending
{
"text": "10\n2\n1",
"direction": "desc",
"caseSensitive": false,
"numeric": true,
"unique": false
}Unique sorted
{
"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
- ECMA-262: ECMAScript Language Specification — Array.prototype.sort — Ecma International
- MDN Web Docs — Array.prototype.sort() — Mozilla
Send feedback
Tell us if this tool helped, report a problem, or suggest a tool. Only the message you type is sent — never the input you used in the tool.
Was this tool useful?
Prefer to write to us directly? See the contact page.