Sort lines alphabetically

Paste a list and put it in order: A to Z, Z to A, numeric, by length or natural. Nothing leaves your browser.

How it works

  1. Paste your lines
  2. Pick an order
  3. Copy the sorted list

The five orders

A to Z and Z to A compare lines letter by letter using English collation, so accented letters sit next to their plain forms: café comes after cafe and before cag, not at the very end of the list. Numeric reads the number at the start of each line, such as 12 in 12 apples or -3.5 in -3.5 kg, and puts the smallest first. Lines that do not start with a number go last, in their original order. By length puts the shortest line first and counts what a person sees as one character, so an emoji or a letter with an accent counts as one. Natural order treats a run of digits as one value, so file2 comes before file10, which plain A to Z would reverse.

Case and ties

Case sensitive is off by default. Apple and apple then rank as equal, and equal lines keep the order they had in your text, so the sort never shuffles lines it cannot tell apart. Turn the option on and the two are told apart: with the same letters, the capital form comes first in A to Z. In numeric and length orders case plays no part, and lines with the same number or the same length also keep their original order. The sort is stable in every mode, so you can sort twice, first by one rule and then by another, and the second pass keeps the first pass wherever it finds a tie.

Blank lines, line endings and digits

A blank line is a line. In A to Z it sorts to the top, in Z to A to the bottom, and in numeric order to the end with the other lines that have no number. A trailing line break at the end of your text creates one blank line, so it moves with the rest. Windows, old Mac and Unix line endings are all read as one break each, and the result uses plain Unix breaks. Numeric order reads digits with an optional sign and one decimal point. It does not read thousands separators, so 1,200 is read as 1, and it does not read 1e3 as one thousand. A number with more than about 300 digits is too big for a computer number, so those lines are ordered by their sign, then by how many digits they have, then by the digits themselves, which is still numeric order.

What this page does not do

It does not remove repeated lines. Sorting puts copies next to each other but leaves them in the list. To drop them, use the remove duplicate lines page, or the list cleaner, which can trim, drop repeats and sort in one pass. It does not shuffle either; for a random order use the shuffle list page. The work happens in this tab and nothing is uploaded. Your choices are remembered in this browser, the text is not. Up to 1,000,000 characters are handled; longer text shows a message asking you to split it.

Frequently asked questions

Why is file10 before file2?

Plain A to Z compares letter by letter, and 1 comes before 2, so file10 lands before file2. Choose Natural and digit runs are compared by value, which gives file1, file2, file10.

Does it sort numbers correctly?

Choose Numeric. It reads the number at the start of each line, with a minus sign or decimals if present, so 9 comes before 10 and -2 before 0. Lines with no leading number, such as a header, go to the end.

Is Apple sorted before banana?

Yes, with the default settings, because case is ignored and A comes before B. Where Apple and apple both appear, they stay in the order you typed them. Turn on Case sensitive to put the capital form first: Apple, then apple, then banana.

Where do blank lines go?

To the top in A to Z, to the bottom in Z to A, and to the end in numeric order. Remove them first with the blank line remover if you do not want them in the list.

Does sorting remove duplicates?

No. Repeated lines end up next to each other and all stay. Use the remove duplicate lines page, or the list cleaner for several clean-ups in one pass.