How to Sort Lines of Text Alphabetically or Numerically
Sort text lines A-Z, Z-A, or by number in the browser. Learn case-sensitive sorting, dedupe, and why natural sort puts file2 before file10.
How to Sort Lines of Text Alphabetically or Numerically
Sorting a list sounds trivial until you actually try it on real data. You paste 200 names and the uppercase ones jump to the top. You sort version numbers and 10 lands before 2. You sort a config block and the indentation falls apart. None of these are bugs in the sort — they're the default rules of string comparison showing through, and once you understand them you can pick the right option instead of fighting the output.
This guide walks through what each sort mode actually does, when case sensitivity matters, why removing duplicates is worth a click, and the one case almost everyone gets wrong: numbers buried inside text. The Text Sorter handles all of it locally, so let's start with what's on the table.
The four ways to order a list
There are really only four orderings you ever need, and the tool exposes all of them:
- Alphabetical (A-Z or Z-A) — the everyday case. Names, tags, CSS class lists, import statements. Ascending puts
applebeforebanana; descending flips it. - Numeric — for lines that are actually numbers: prices, IDs, HTTP status codes, line counts. This compares the value, not the characters.
- By length — sorts shortest to longest (or the reverse). Genuinely useful for finding the one config value that blew past an 80-character limit, or the longest headline in a list of options.
- Reverse — no comparison at all, it just flips the existing order. Perfect for turning an oldest-first changelog into newest-first without re-parsing any dates.
The key thing: you can sort lines alphabetically or numerically, ascending or descending, with case-sensitive and dedupe options layered on top. They combine. Numeric + descending gives you a leaderboard. Alphabetical + dedupe gives you a clean unique index.
Why "10" sorts before "2" (and how to fix it)
This is the single most common surprise. Take this list of error codes:
2
10
100
404
500
Run a plain alphabetical sort and you get:
10
100
2
404
500
That looks broken, but it's correct for string comparison. A string sort reads character by character: it compares the first character of "10" (the digit 1) against the first character of "2" (the digit 2), decides 1 comes before 2, and stops. It never even looks at the rest of the number. So "10" and "100" both sort ahead of "2".
Switch the mode to numeric and the same list comes out the way you'd expect:
2
10
100
404
500
Now the tool reads each line as a value, so 2 < 10 < 100. Use numeric sort whenever every line is a number — prices, IDs, ports, response codes. Use alphabetical for text. Mixing them is where the trouble starts.
Natural sort: numbers inside strings
The trickier version of the same problem is when numbers are embedded in text — filenames, version tags, chapter labels. Consider:
file1
file2
file10
file20
A plain string sort produces file1, file10, file2, file20 — file10 jumps ahead of file2 for exactly the reason above: it compares 1 against 2 at the digit position and stops. That's almost never what you want when you're looking at a file list.
Natural sort fixes this by treating runs of digits as whole numbers instead of individual characters. So it sees file2 as "file" + the number 2, file10 as "file" + the number 10, and orders them numerically: file1, file2, file10, file20. The short version everyone remembers: natural sort puts file2 before file10, while plain string sort puts file10 first. If your list mixes a text prefix with a numeric suffix — v1.9 vs v1.10, chapter-3 vs chapter-12, img-7 vs img-30 — natural ordering is what makes the result match human intuition.
Case sensitivity and duplicates
Two small options that change a lot.
Case sensitivity. By default many sorts are case-aware, and in ASCII every uppercase letter has a lower codepoint than every lowercase one. That means Z (codepoint 90) sorts before a (97). So a case-sensitive A-Z sort of apple, Banana, Zebra, cherry gives you Banana, Zebra, apple, cherry — all the capitalized words first, then the lowercase ones. If you want the dictionary order a reader expects, turn case sensitivity off and you get apple, Banana, cherry, Zebra. Keep it on only when capitalization is meaningful, like sorting constant names where MAX_SIZE and maxSize are genuinely different identifiers.
Remove duplicates. Flip this on and identical lines collapse to one. It pairs beautifully with a sort because duplicates sit next to each other after ordering, so the dedupe is exact and visible. Exporting 200 RSVPs and six people registered twice? Sort A-Z, enable dedupe, and you're down to 194 clean lines. If you need more control over near-duplicates — case-insensitive matching, trimming whitespace before comparing — the dedicated Text Deduplicator gives you those knobs without re-sorting anything.
A worked example, start to finish
Say a teammate hands you this release list, pasted in the order they happened to type it:
v1.2
v1.10
v1.1
v1.9
v1.20
You want newest-version-last, cleanly ordered. A naive alphabetical sort gives you v1.1, v1.10, v1.2, v1.20, v1.9 — v1.10 ahead of v1.2, v1.9 dead last. Wrong on two counts. Run it through natural sort instead and the digit runs get compared as numbers:
v1.1
v1.2
v1.9
v1.10
v1.20
Every version lands where it belongs. That single difference — v1.9 before v1.10 instead of after v1.2 — is the whole reason natural ordering exists.
Everything stays on your machine
I sort lists constantly while writing release notes, and the reason I keep this tool pinned is that I never have to think about where the text goes. Every sort runs in the browser through Array.sort() with the Intl.Collator API. The input never leaves the tab, nothing is logged, and there's no upload step to wait on. The one caveat: if you use the share link, your lines get encoded into the URL so the recipient sees the same result — handy for sharing a sorted list with a colleague, but don't do it with confidential names or keys. Plain sorting in the tab keeps everything local, which is exactly what you want when the list is a customer export or an internal config file.
That local-first design is also why it's fast. There's no round trip to a server, so even a few thousand lines sort the instant you change a mode. Paste, pick your ordering, toggle case and dedupe, copy the result. For counting what you ended up with, the Word Counter gives you line and character totals in the same browser-only way.
Made by Toolora · Updated 2026-06-13