Sort any list of lines into alphabetical or numerical order
Sort any block of text lines alphabetically, reverse alphabetically, or numerically.
Interactive Sample Data
| id | line |
|---|---|
| 1 | Mombasa |
| 2 | Nairobi |
| 3 | Eldoret |
How this tool works
Things that usually go wrong
- Standard (string) sort puts '10' before '2' because '1' < '2' in ASCII — use 'sort numerically' to fix this.
- Mixed-script lines (some Latin, some Arabic) sort by Unicode code point, which may not match user expectations — sort Latin lines separately.
- Lines ending with Windows CRLF (\r\n) may sort after equivalent Unix LF (\n) lines — the tool normalises line endings before sorting.
Edge cases we tested
Sorted 2, 9, 10, 100 — numeric value used, not string comparison.
Leading spaces are significant in default sort; space sorts before letters in ASCII.
Both lines kept; their relative order matches the original input (stable sort).
Blank lines sort to the top in ASCII order by default; use 'remove blank lines' to eliminate them first.
Returned unchanged — sorting one line produces one line.
Frequently Asked Questions
Does sorting remove duplicate lines?
No — it only reorders them. Use 'Remove Duplicate Lines' before or after sorting to collapse duplicates.
Can I sort in reverse alphabetical order?
Yes — add 'Z to A' or 'reverse' to your instruction.
Is the sort stable?
Yes. Lines that compare as equal preserve their original relative order.
Can I sort by the second word on each line?
Add 'by the second word' to your instruction — the engine uses the second space-delimited token as the sort key.
Related tools
Remove Duplicate Lines
Remove repeated lines from any text block, with options for case sensitivity and whitespace handling.
Open Tool →Remove Empty Lines
Remove all blank and whitespace-only lines from any block of text.
Open Tool →Remove Extra Spaces
Collapse multiple consecutive spaces into one and strip leading/trailing spaces from any text.
Open Tool →Sort CSV by Column
Sort tabular CSV records ascending or descending by any column value.
Open Tool →