Sort Lines

A sort lines tool puts the lines of a list in order. Paste your list, one item per line, and choose alphabetical A to Z or Z to A, natural order, a number in each line, line length or a random shuffle. You can ignore case and remove duplicates. Everything runs in your browser.

Runs in your browser. Your text is never uploaded.

How to use the sort lines

  1. Paste your list into the first box, one item on each line. The sorted result appears beside it, or underneath on a phone, as you type or paste.
  2. Choose how to sort. Alphabetical suits most lists. Pick Natural when lines contain numbers, such as file names, so that item 2 comes before item 10.
  3. Choose the order: A to Z (smallest or shortest first) or Z to A (largest or longest first).
  4. Tick the options you need: ignore upper and lower case, remove empty lines, remove duplicate lines or trim spaces. Then press Copy result or Download .txt.

How the lines are sorted

The tool splits your text at every line break, applies the options you ticked, then sorts. It follows these steps.

  1. Split into lines. Line breaks from Windows, Mac and Linux are all understood.
  2. Clean up, if asked. Trim removes spaces and tabs at the start and end of each line. Remove empty lines drops lines that are empty or hold only spaces. Remove duplicate lines keeps the first copy of each line and drops later copies, ignoring case if that box is ticked.
  3. Compare. Alphabetical order uses the Unicode Collation Algorithm through your browser's built-in collator, so accented letters sit next to their plain forms (é next to e) instead of after z. Spaces at the ends of a line are ignored when comparing, but the line is written out exactly as you typed it.
  4. Upper and lower case. With Ignore upper and lower case ticked, Apple and apple count as equal and keep the order you gave them. Untick it and the capital letter comes first when two lines are otherwise the same.
  5. Natural order reads runs of digits as whole numbers, so item 2 sorts before item 10. Plain alphabetical order compares digit by digit, which puts item 10 first because 1 comes before 2.
  6. Number in the line sorts by the first number found in each line. It understands a minus sign, thousands commas and a decimal point, so −30, 4.50 and 1,250 sort as numbers. Lines with no number go to the end.
  7. Line length counts characters, not bytes, so an emoji or an accented letter counts as one.
  8. Reverse flips your list upside down without sorting it, and Random shuffles it fairly using your browser's secure random number generator. Press Shuffle again for a new order.

Lines that compare as equal keep the order they had (a stable sort), so sorting twice gives the same result.

Worked example

This list has seven lines, including one empty line, two spellings of apple and two numbered items:

banana
Apple
item 10
cherry

apple
item 2

With the default settings the empty line is removed and case is ignored, so Apple and apple count as equal and keep their original order. Plain alphabetical order puts item 10 before item 2, because it compares the 1 with the 2. Natural order fixes that. In the table, ↵ marks the end of a line.

SettingResult
Alphabetical, A to Z (default)Apple↵apple↵banana↵cherry↵item 10↵item 2
Alphabetical, Z to Aitem 2↵item 10↵cherry↵banana↵Apple↵apple
Natural, A to ZApple↵apple↵banana↵cherry↵item 2↵item 10
Natural, A to Z, remove duplicate linesApple↵banana↵cherry↵item 2↵item 10
Line length, shortest firstApple↵apple↵banana↵cherry↵item 2↵item 10

Sorting by the number in each line works on lists such as a budget. These four lines, sorted smallest first, come out as Refund -30↵Coffee 4.50↵Books 89↵Rent 1,250.

Which sort order to use

Sort byWhat it doesGood for
AlphabeticalA to Z by letters, accents next to their plain lettersNames, words, tags, keywords
NaturalLike alphabetical, but reads 10 as ten, not as 1 then 0File names, chapters, versions, numbered items
Number in the lineBy the first number in each line; lines without one go lastPrices, scores, amounts, measurements
Line lengthBy the number of characters in each lineFinding the shortest or longest entries
Reverse current orderFlips the list upside down without sortingPutting a log or a timeline newest first
Random (shuffle)Puts the lines in a fair random orderDraws, quiz questions, picking an order to present

Frequently asked questions

How do I alphabetize a list?

Paste the list with one item on each line, leave Sort by on Alphabetical and Order on A to Z, and copy the result. Choose Z to A for reverse alphabetical order.

Why does item 10 come before item 2?

Alphabetical order compares one character at a time, and 1 comes before 2. Choose Natural (2 before 10) to read runs of digits as whole numbers.

Does sorting change the text of my lines?

No. Lines are written out exactly as you typed them, spaces included. They change only if you tick Trim spaces at the start and end of lines.

Can I sort and remove duplicates at the same time?

Yes. Tick Remove duplicate lines and the first copy of each line is kept. To remove duplicates without sorting, use the duplicate line remover, which keeps your original order.

Is the shuffle really random?

It uses the Fisher–Yates shuffle with your browser’s cryptographic random number generator, so every order of the lines is equally likely.

Is my list uploaded or stored?

No. The sorting happens in your browser and your text never leaves your device.

Sources and references