Sort Lines
Private: nothing leaves your browser
Waiting for text
Paste a list and sort it alphabetically, in reverse, in natural order so item2 comes before item10, by line length, or shuffle it into a random order. Accents and capitals are handled the way a reader expects, not the way a byte comparison does.
About sorting lines
Sorting a list is the sort of thing a spreadsheet will do, once you have pasted the list into a column, told it there is no header row and clicked through a dialog. Here you paste and read the answer. The list can be names, file paths, SQL column names, a bibliography or a shopping list: it is all just lines. If those lines also need the same change made to every one of them, Find and Replace is the other half of the job.
The comparison is done with the browser's own Intl.Collator rather than a raw character code comparison, and that difference is visible immediately on real data. A byte comparison puts every capital letter before every lowercase letter, so "Zebra" lands ahead of "apple", and it puts accented letters after "z" entirely, so "Ångström" ends up at the bottom. A collator sorts them where a reader would look for them.
Natural order is the one people usually mean and rarely get. It reads runs of digits as numbers, so item2 comes before item10, and chapter 9 before chapter 10, instead of the plain alphabetical order that puts every number starting with a 1 together. It is the right choice for filenames, version strings and anything numbered.
Shuffle uses crypto.getRandomValues and a Fisher-Yates walk. That is not fussiness: the popular one-liner that sorts by a random comparator produces a measurably uneven shuffle, because the result depends on the sorting algorithm underneath it. If you are drawing a winner or randomising an exam order, it should actually be random.
How to sort lines
- Paste your list into the left box, one item per line.
- Pick the Order you want. The result updates immediately.
- Tick Case sensitive if capitals should sort separately from lowercase.
- Tick Ignore indentation to sort an indented list by its text rather than its spaces.
- Tick Remove blank lines so empty lines do not collect at one end.
- Press Copy, or Result to input to sort the result again a different way.
Common questions about sorting lines
What does natural order actually do?
Why do capitals and lowercase mix together?
Is the shuffle actually random?
crypto.getRandomValues, with rejection sampling so that no index is slightly more likely than another, and a Fisher-Yates walk so that every possible ordering is equally likely. It is safe to use for drawing a winner from a list of names.
Does it remove duplicate lines too?
Does it keep my indentation and blank lines?
Can I sort a list I am not allowed to upload?
Next