Free Online Sort Lines, A to Z, By Number, By Length, Random & Reverse
Put a list in order. Alphabetically in either direction, by the number a line starts with, by how long the line is, or shuffled at random. Natural ordering puts file 2 before file 10 rather than after it, and you can ignore case, ignore leading spaces, or sort by a chosen column of a delimited list.
Letter by letter, 1 comes before 2, so 10 sorts before 2.
file 2
file 10
Natural order reads the digits as one number instead.
Natural order is on by default here, because it is what people mean.
Plain alphabetical sorting compares one character at a time, and the character 1
really does come before the character 2, so file 10 lands before file 2 and invoice
100 before invoice 9. Natural order pulls out the runs of digits and compares them
as numbers. Switch it off when you want the strict alphabetical order a computer
would use, which is sometimes exactly what a system on the other end expects.
Shuffling uses your browser's cryptographic random source, not the usual trick.
The common way to shuffle a list is to sort it with a random comparison, and that does
not give every order an equal chance: some arrangements come up far more often than
others. This uses a proper shuffle, walking the list from the end and swapping, with
the bias that comes from taking a remainder removed. On a two line list run six
thousand times the split came out within a couple of percent of even.
Where Your Text Goes
Nowhere. And you can check that yourself.
A list worth sorting is usually a list worth keeping private, and this page never receives it.
The text is read and changed by your own browser. Press F12, open the Network tab,
and use the tool: the page fetches its own code and nothing else. Or load the page,
turn off your wifi, and carry on working. It still runs, because there was never a
server in the middle.
How to Sort a List of Lines
Four steps, and your original text is never changed.
1
Paste your listOne item per line. A .txt or .csv file can be opened or dropped on the box.
2
Pick an orderA to Z, Z to A, by the number in the line, by length, reversed, or shuffled at random.
3
Decide how strict the comparison isIgnoring case and leading spaces is usually what you want. Natural order keeps item 2 before item 10.
4
Copy or downloadOr press Use as input to run something else on the sorted list, like removing duplicates.
What to Know Before You Sort
Including the things this tool cannot do.
Natural order is on by default, and that is a decision worth knowing about. With it on, file 2 comes before file 10 because the digits are read as a number. With it off you get strict alphabetical order, where 10 sorts before 2. Neither is wrong: the first is what people expect, the second is what a database or a file system will often do.
Ignoring case changes the comparison, not the text. With it on, Apple and apple sort next to each other instead of all the capitals coming first. The lines you get back are exactly as you pasted them; nothing is lowercased. With it off, every capital letter sorts before every lowercase one, which is why a list can come out looking split in two.
Sorting by number puts the lines without numbers at the end. They are not dropped and they are not silently reordered among themselves; they simply have nothing to compare. The page says how many of them there were, because a list that seems to have lost its last few lines is usually this.
Sorting by column needs the same separator on every line. The line is split on the character you choose and the chosen piece is compared. A line with fewer columns than you asked for compares as empty, so it sorts to the top rather than being skipped. Quoted commas inside a CSV field are not understood, and that is a real limit rather than an oversight: doing it properly means parsing CSV, which is a different tool.
Key Features & Capabilities
What this tool does, and what it deliberately does not.
Six ordersA to Z, Z to A, by number, by length, reversed and shuffled.
Natural numberingItem 2 before item 10, which is what a list of files or invoices needs.
Sort by a columnSplit on a tab, comma, semicolon, pipe or space and sort by any piece.
A proper shuffleFisher-Yates with a cryptographic source, not the biased sort trick.
Case and space switchesDecide what the comparison ignores, without changing the text itself.
Nothing uploadedYour list stays in your tab from start to finish.
About the Sort Lines
Sorting a list is the kind of thing a spreadsheet does well and a text file does not. Getting a column of names, codes or URLs into order usually means pasting it into a spreadsheet, sorting, and pasting it back, which is three steps and two chances to lose the formatting.
This does it in place, as you type, with the orders people actually need: alphabetical either way, by the number inside the line, by length, reversed, and shuffled. It also does the one thing plain sorting always gets wrong, which is putting file 2 before file 10 instead of after it.
The switches are on the page rather than assumed. Whether case matters, whether leading spaces count, whether blank lines survive, and which column to sort by are all decisions a sorting tool makes for you silently. Here they are visible, and the result changes while you look at it.
Frequently Asked Questions
Natural order, columns, and where the lines without numbers go.
Natural order is switched off, so the comparison is character by character and the character 1 comes before 2. Switch natural order back on and the digits are read as whole numbers, which puts 2 first.
No. Sorting only changes the order, so duplicates end up next to each other and stay. Press Use as input and open the Remove Duplicate Lines tool if you want them gone as well.
Yes. Switch on the column option, set the number to 3 and the separator to a comma. The one thing it does not understand is a comma inside a quoted field, which will shift the columns for that line. For files with quoted commas, use a spreadsheet.
To the end of the list, and the page tells you how many there were. Sorting by number has nothing to compare them with, so they are grouped at the bottom rather than dropped or scattered.
It uses your browser's cryptographic random source with the remainder bias removed, and a Fisher-Yates walk rather than a random sort comparison. On a two line list run six thousand times, each line came first close to three thousand times.
Every Other Text Tool
24 more tools in this set. All free, all in your browser.