The Complete Guide to Sorting Text Lines
Alphabetical, natural and numeric sorting disagree on the same list. Measured against GNU sort: natural order puts -5 before -10 and 10.5 before 10.25, case-sensitive sorting is not ASCII order, and our shuffle now uses crypto randomness.
Three Different Things Called "Sorting"
Alphabetical, natural and numeric order disagree on the same list. We ran one list through each mode of our Sort Lines tool and through GNU sort (October 2026; results in our test folder):
| Input | Alphabetical (A-Z) | Natural (1-9) | Number value (like sort -g) |
|---|---|---|---|
| Item 2, Item 10 | Item 10, Item 2 | Item 2, Item 10 | — |
| v1.2, v1.10, v2.0 | v1.10, v1.2, v2.0 | v1.2, v1.10, v2.0 | — |
| -5, -10, 0.25, .5, 10.25, 10.5 | -10, -5, .5, 0.25, 10.25, 10.5 (by characters) | -5, -10, .5, 0.25, 10.5, 10.25 | -10, -5, 0.25, .5, 10.25, 10.5 |
| 1e3, 999 | 1e3, 999 | 1e3, 999 | 999, 1e3 |
Natural order compares runs of digits as numbers, which is right for file names and versions, but it reads - and . as plain characters, so it puts -5 before -10 and 10.5 before 10.25. For actual numbers (prices, measurements, scientific notation) use the number-value mode, which matched GNU sort -g on all 24 lines of our test list.
What "Alphabetical" Means in Practice
The tool compares with the browser's Intl.Collator, the Unicode collation algorithm for your language, not character codes. So accented letters sort beside their base letter in English (e, é, f; n, ñ, o), but in Swedish å, ä and ö come after z, as they do in that alphabet. Two people with different browser languages can get different orders for the same list.
Case: by default upper and lower case are treated alike. With case-sensitive sorting on, the order is still dictionary order with case as a tie-break (apple, Apple, B, banana, Cherry in our test), not the ASCII order of some command-line tools, where every capital comes before every lowercase letter. For ASCII order, use LC_ALL=C sort.
Length, Reverse and Shuffle
- Length sorts by character count, handy for finding the longest URL or shortest name in a list.
- Reverse flips the current order without comparing anything.
- Shuffle is a Fisher-Yates pass driven by
crypto.getRandomValues(). In 240,000 shuffles of four lines all 24 possible orders appeared 9,784-10,191 times, consistent with equal chances (chi-square 27, 1% critical value 41.6). Until this check the tool usedMath.random(), which is predictable; we changed it so shuffles can be used for draws.
Ties Keep Their Order
Lines that compare equal stay in their original order, because JavaScript's sort has been required to be stable since ECMAScript 2019, and the column and ignore-prefix options add the original position as an explicit tie-breaker. That makes multi-pass sorting work: sort by the secondary key first, then by the primary key.
Try the tool
8 sort modes, international support, runs in your browser.
Frequently Asked Questions
Why does '10' sort before '2' alphabetically?
Does it handle international characters?
Is shuffle cryptographically random?
Can I sort by multiple criteria?
Published Apr 15, 2026 · Updated Oct 13, 2026 by Derek Giordano
Browse all utility tools →