Text Sorter
Put a list in order — alphabetical, numeric, by length or shuffled — without leaving the page.
What the text Sorter does
Sorting a list is the sort of thing a spreadsheet does well and a text editor usually does not. This tool takes a list of lines and orders it four ways: alphabetically, by line length, by the first number found on each line, or in a random shuffle.
Alphabetical sorting uses the browser's Intl.Collator, which sorts according to real
language rules rather than raw character codes. That difference is not cosmetic: a naive sort places
every capital letter before every lowercase one, so Zebra lands before
apple. Collator-based sorting also handles accented characters correctly, placing
éclair where a reader would expect it rather than after z.
Natural number ordering is on by default and is usually what you want. Without it,
item10 sorts before item2, because character by character
1 comes before 2. With it, embedded numbers are compared as numbers, so
files, versions and numbered items come out in human order.
Sorting by the first number on a line is a different operation: it ignores the text entirely and
reads the first numeric value it finds, including negatives and decimals. That makes it work on
lines like Widget A — 42 units. Lines with no number sort to the end rather than
being treated as zero, so they are easy to spot and fix. The random shuffle uses a Fisher–Yates
algorithm, which gives every ordering an equal chance — unlike the common trick of sorting
with a random comparator, which is measurably biased.
How to use it
- Paste your list into the left box, one item per line. Blank lines are ignored.
- Choose a sort mode and set the options — natural ordering and case-insensitive matching suit most lists.
- Copy the sorted result or download it as a text file.
A worked example
A mixed list with inconsistent capitalisation and embedded numbers:
item10
Banana
item2
apple
item1
Cherry
banana
Sorted alphabetically, case-insensitive, with natural number ordering and duplicates removed:
apple
Banana
Cherry
item1
item2
item10
Three things happened there. banana was dropped as a duplicate of
Banana; capitals and lowercase were interleaved rather than segregated; and the numbered
items came out 1, 2, 10 instead of 1, 10, 2. Turn natural ordering off and that last group reverts
to the raw character order, which is what a plain sort command would give you.
Frequently asked questions
Why does sorting put lowercase and uppercase words together?
Because the case-insensitive option is on by default, which is nearly always what people expect from an alphabetical list. Turn it off and the sort becomes case-sensitive, grouping capitals separately in the way a raw byte-order sort would.
What does natural number ordering do?
It compares embedded digit sequences as numbers rather than characters, so file2 comes before file10. It is the difference between a list that reads correctly and one that looks broken to anyone scanning it.
What happens to lines with no number when sorting numerically?
They are pushed to the end of the list rather than being treated as zero, which keeps them visible so you can decide what to do with them instead of silently mixing them into the data.
Is the random shuffle actually random?
It uses a Fisher–Yates shuffle, which produces every possible ordering with equal probability. It draws on Math.random, so it is fine for picking a winner or reordering a playlist but is not cryptographically secure and should not be used where the outcome must be unpredictable to an adversary.