webtools

Sort Lines

Private: nothing leaves your browser

Sorted lines
output

                  

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

  1. Paste your list into the left box, one item per line.
  2. Pick the Order you want. The result updates immediately.
  3. Tick Case sensitive if capitals should sort separately from lowercase.
  4. Tick Ignore indentation to sort an indented list by its text rather than its spaces.
  5. Tick Remove blank lines so empty lines do not collect at one end.
  6. 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?

It reads any run of digits inside a line as a number rather than as characters. Alphabetically, item10 comes before item2, because "1" is before "2". In natural order you get item1, item2, item10, which is what you meant. Use it for filenames, chapter headings, version numbers and anything else that is numbered.

Why do capitals and lowercase mix together?

By default "Apple" and "apple" are treated as the same word for sorting, which is how a dictionary or a phone book works. Tick Case sensitive if you need capitals kept apart, which matters for things like case sensitive identifiers or a checksum list.

Is the shuffle actually random?

Yes. It uses your browser's cryptographic random source, 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?

No, sorting keeps every line, and repeated lines simply end up next to each other. If you want them gone, run the list through Remove Duplicate Lines first and then sort what is left.

Does it keep my indentation and blank lines?

Yes to indentation: the line is copied exactly as you typed it, and Ignore indentation only changes what is compared, not what comes out. Blank lines are kept as lines unless you tick Remove blank lines. Windows line endings are preserved too, so a list pasted from a Windows file goes back the same way.

Can I sort a list I am not allowed to upload?

Yes. The sorting is JavaScript running on this page, so a list of staff names or internal hostnames stays on your own device. Nothing is sent, logged or saved, and the page keeps working with your connection switched off.

Next

Related tools

All Text tools