How to sort lines alphabetically, and why item10 keeps jumping the queue
Paste a list, choose one of eight orders, copy it back out. Natural numbering is on by default, so item2 lands before item10.
Alphabetizing a list is the kind of task that takes two seconds in a spreadsheet and fifteen minutes if you have to open one first. The Sort Lines tool takes a block of text, one item per line, and reorders it while you watch.
How it works
- Paste your list into the top box with one item on each line.
- Pick a sort order. A to Z and Z to A handle text, the numeric modes read the first number on each line, and length sorts by character count.
- Check the line counts, then copy the result. Nothing is submitted anywhere; the sort runs in the page.
Natural sort, or why 10 keeps beating 2
Give a plain alphabetical sorter these five lines:
item1, item2, item10, item11, item20
and it returns item1, item10, item11, item2, item20. Nothing is broken. A string comparison walks left to right and compares one character at a time, and the character 1 sorts before the character 2, so anything starting "item1" beats everything starting "item2" no matter how long it is.
Natural sort reads consecutive digits as a single number before comparing. item2 becomes item followed by 2, item10 becomes item followed by 10, and 2 is less than 10, so the order comes out the way a human would write it. This tool has natural sort ticked by default, which is the opposite of most online sorters. Untick it if you specifically need raw character order, which is what a database index or a sort shell command without -V would give you.
The three toggles
Case-sensitive is off by default so Apple and apple end up next to each other. Turn it on and every capitalised line moves ahead of the lowercase ones, because uppercase letters carry lower character codes.
Ignore leading whitespace changes only what gets compared. Indented lines sort by their content but keep every space and tab they arrived with, which matters when the list is a chunk of code or a nested outline.
Remove blank lines drops empty rows before sorting. Without it, blanks are empty strings and collect at the top of an A to Z sort. The counters under the options show lines in, lines out and how many were removed, so you can see exactly what the toggle did.
Reverse and shuffle are not sorts
Reverse order flips the list as it stands and ignores the alphabet entirely. It is the fastest way to invert a log file or a changelog. Shuffle uses a Fisher-Yates pass over the array with values from crypto.getRandomValues where the browser offers it. The trick you see in a lot of code, sort(() => Math.random() - 0.5), is not a fair shuffle and leaves short lists suspiciously close to where they started.