Text Sorter
Sort lines alphabetically, in natural number order, by length, in reverse or at random.
Seven ways to order a list
Paste a list, pick an order and the sorted version appears immediately. The choice of order matters more than it looks: plain alphabetical order puts item 10 before item 2, which is correct by the rules of the alphabet and wrong by the rules of common sense.
The table shows every mode applied to the tool's sample list of six lines: item 10, Banana, item 2, apple, Cherry, item 1.
| Mode | Result |
|---|---|
| A to Z | apple, Banana, Cherry, item 1, item 10, item 2 |
| Z to A | item 2, item 10, item 1, Cherry, Banana, apple |
| Natural | apple, Banana, Cherry, item 1, item 2, item 10 |
| Shortest first | apple, Banana, item 2, Cherry, item 1, item 10 |
| Longest first | item 10, Banana, item 2, Cherry, item 1, apple |
| Reverse order | item 1, Cherry, apple, item 2, Banana, item 10 |
| A to Z, case-sensitive | Banana, Cherry, apple, item 1, item 10, item 2 |
Case-sensitive is off unless stated. Shuffle is random, so it has no fixed result.
Shortest first and longest first count characters, with an emoji or accented letter counting as one. Lines of equal length keep the order they had in the input, which is why Banana stays ahead of item 2 and Cherry, all six characters long. Reverse order does not sort at all: it flips the list upside down, which is handy for turning a newest-last log into a newest-first one.
Natural sort: why 2 should come before 10
Alphabetical sorting compares text one character at a time. In file10 and file2, the first difference is 1 against 2, and 1 comes first, so file10 wins. A natural sort reads each run of digits as a whole number instead, so 2 is compared with 10 and the result matches what a person expects.
| Input | A to Z | Natural |
|---|---|---|
| file10.txt, file2.txt, File1.txt, file1.txt, file20.txt | File1.txt, file1.txt, file10.txt, file2.txt, file20.txt | File1.txt, file1.txt, file2.txt, file10.txt, file20.txt |
| v1.10.0, v1.2.0, v1.9.3, v2.0.0, v1.2.10 | v1.10.0, v1.2.0, v1.2.10, v1.9.3, v2.0.0 | v1.2.0, v1.2.10, v1.9.3, v1.10.0, v2.0.0 |
The second row shows a useful side effect: natural order sorts simple version numbers correctly, because each dotted part is a separate number. It is not a full semantic-versioning sort, though. Pre-release tags such as -beta are compared as text, so check those by hand.
Case-sensitive or not
With Case-sensitive off (the default), capitals are ignored for ordering: apple, Banana and Cherry come out in dictionary order. Accented letters sort next to their plain forms, so eclair and Eclair with an accent sit together, and Apfel with an umlaut lands beside apple rather than after zebra.
With Case-sensitive on, lines are ordered by their raw character codes. All capitals come before all lowercase letters, and accented letters come after z. That gives Banana, Cherry, apple, which looks odd but is exactly how many programming languages and command-line tools sort by default. Use it when you need output that matches such a system.
Where two lines are equal apart from case, such as File1.txt and file1.txt, the capitalized one is placed first so the result is the same every time.
Removing duplicates and empty lines
Two options clean the list before it is sorted. Remove empty lines drops blank and whitespace-only lines, which otherwise collect at the top of an A to Z sort. Remove duplicates keeps one copy of each line, following the same case rule as the sort.
For example, the seven lines pear, blank, Pear, fig, pear, blank, kiwi with both options on give fig, kiwi, pear: three lines, four removed. Turn on Case-sensitive and Pear counts as different from pear, giving Pear, fig, kiwi, pear: four lines, three removed. The line count above the output shows how many lines were removed.
Shuffling fairly
Shuffle uses the Fisher-Yates algorithm with random numbers from your browser's cryptographic generator (crypto.getRandomValues), the same source used for passwords and keys. Every possible order is equally likely, which is not true of the common shortcut of sorting by a random comparison, a method known to favor some orders over others.
That makes it suitable for picking a running order for presentations, randomizing quiz questions or drawing names for a small raffle. For anything with legal or financial stakes, such as a regulated prize draw, follow the rules that apply to you and keep a record of how the draw was made.
Good to know
- Line endings: Windows (CRLF) and Unix (LF) line breaks are both understood, and the output keeps the style of the input.
- Stable sorting: lines that compare as equal keep their original relative order.
- Numbers with decimals or signs: natural sort treats digit runs as whole numbers, so 1.5 is read as 1, then 5. For a list of decimal or negative numbers, a spreadsheet's numeric sort is more reliable.
- Large lists: tens of thousands of lines sort in a fraction of a second.
- Same result everywhere: alphabetical order follows English collation rules on every device, so a list sorted here comes out the same for a colleague in another country. Languages with their own alphabet order, such as Swedish placing accented letters after z, may differ from a local dictionary.
- Leading spaces count as characters. An indented line sorts before unindented ones in A to Z order; tidy the list with the Remove Extra Spaces tool first if that is not what you want.
Frequently Asked Questions
How do I sort a list alphabetically?
Paste the list with one item per line and click A to Z. Capitals are ignored by default, so apple, Banana and Cherry come out in dictionary order. Click Copy to take the result.
Why does 10 come before 2 when I sort?
Alphabetical sorting compares character by character, and the character 1 comes before 2. Choose Natural instead, which reads each run of digits as a whole number so item 2 comes before item 10.
What is natural sort order?
An ordering that treats numbers inside text as numbers rather than characters. It gives file1, file2, file10 instead of file1, file10, file2, which is how most people expect a list to read.
What does case-sensitive sorting do?
It orders lines by raw character codes, so every capitalized line comes before every lowercase one: Banana and Cherry before apple. Leave it off for normal dictionary order.
Can I sort lines by length?
Yes. Shortest first and Longest first order lines by their number of characters. Lines with the same length keep their original order.
How do I reverse the order of lines?
Click Reverse order. It flips the list without sorting it, so the last line becomes the first. Click A to Z then Z to A if you want reverse alphabetical order instead.
Is the shuffle truly random?
It uses the Fisher-Yates shuffle with your browser's cryptographic random number generator, so every order is equally likely. Click Shuffle again for a new order.
Can I remove duplicates while sorting?
Yes. Tick Remove duplicates to keep one copy of each line. It follows the case setting, so Pear and pear count as the same line unless Case-sensitive is on.
Is my text uploaded anywhere?
No. Sorting happens entirely in your browser and nothing is sent to a server.