How to Sort Lines of Text Online (and Why 10 Sorts Before 9)
A practical guide to sorting lists in the browser — alphabetical, numeric, and by length, plus how to strip duplicates that uniq misses.
I keep a scratch file of every domain I’ve ever registered. About 200 lines, added in whatever order I happened to buy them, and every few months I want to see it alphabetised. Opening Excel for that feels absurd. Writing a sort command means looking up which flags I need. So instead: paste, click, copy.
That’s the entire job of the Text Line Sorter.
The 10-before-9 problem
This is what trips up most people the first time. Sort these three lines alphabetically:
item 9
item 10
item 2
You get item 10, item 2, item 9. That’s not a bug. Alphabetical sorting compares character by character, and “1” comes before “2” and “9” in every character table ever made. The sort never sees the number ten. It sees the character “1”, then “0”.
Numeric mode fixes this by pulling the first number out of each line and comparing values instead of characters. Lines with no number in them sink to the bottom, which is usually where you want stray headers and half-finished entries anyway.
Duplicate removal, and why uniq lies to you
If you’ve ever run this on the command line and wondered why duplicates survived:
uniq contacts.txt
uniq only collapses duplicate lines that sit next to each other. Two identical entries 400 lines apart are invisible to it. You actually need sort contacts.txt | uniq, or just sort -u contacts.txt.
The Remove duplicates checkbox has no such gotcha. It scans the whole list, keeps the first occurrence of each line, and reports how many it dropped. It ignores case by default, so “Apple” and “apple” collapse into one entry. Tick Case sensitive if that’s wrong for your data.
Sorting by length
The least obvious mode, and the one I reach for more than I expected. It’s good for:
- Finding the outlier — the one URL in a redirect map that’s suspiciously long
- Spotting truncated entries, which cluster at the top
- Eyeballing a list of IDs for ones that don’t match the expected format
Ties fall back to alphabetical order, so lines of equal length still come out predictably instead of in whatever order the browser felt like that day.
The locale thing nobody mentions
Sorting isn’t universal. Run LC_ALL=C sort on a Unix box and it compares raw bytes, which puts every uppercase letter ahead of every lowercase one and dumps accented characters somewhere past Z. That’s how you end up with “Zebra” before “apple”.
This tool uses the browser’s locale-aware comparison instead. Å sorts next to A. Ё sorts next to Е. Uppercase and lowercase interleave the way a person would file them in a drawer, not the way a byte comparison would.
Nothing leaves your browser
The sort runs in JavaScript, in your tab. No upload step and no server queue. Load the page, switch off your wifi, and it keeps working.
That matters more than it sounds like it should. A good share of the lists people want sorted are exactly the kind you shouldn’t paste into a random website: customer emails, internal hostnames, exported user IDs.
Paste your list into the Text Line Sorter and it re-sorts as you type.