Line Sorter & Deduplicator

Sort lines alphabetically or numerically, reverse them, shuffle them, or remove duplicates — with natural sort for text containing numbers.

Dictionary order is not character-code order

Comparing text with < gives code-point order, which puts every capital before every lower-case letter: Z is 90 and a is 97, so Z wins. Comparing with localeCompare gives dictionary order, which interleaves them. Across the 8,930 ordered pairs of printable ASCII characters the two disagree on 2,198 — 24.6%:

PairDictionary orderCode-point order
a vs B a first B first differ
Z vs a a first Z first differ
_ vs a _ first _ first agree
1 vs ! ! first ! first agree

This page uses localeCompare, which is the right choice for a list of words and the reason a capitalised entry is not hoisted to the top. If a sort here disagrees with one in a spreadsheet or a terminal, this is almost always why, and neither is broken.

And numbers are not numbers

A list of numbers is a list of text, and text sorts one character at a time:

Order
as typed1 2 10 9 100 20
sorted here1 10 100 2 20 9
numeric order1 2 9 10 20 100

"10" comes before "2" because "1" comes before "2" and nothing after that matters. It bites version numbers, file names, invoice numbers and anything else where digits mean a quantity. Padding to a fixed width fixes it — 01, 02, 09, 10 sorts correctly as text — which is why so much machine-generated data is zero-padded.

The ignore-case box does far less than its label suggests

localeCompare is already case-insensitive as its primary comparison — case is only a tie-break. So apple, Mango, Zebra comes out in that order with the box off, which is the behaviour people tick it for. They already had it.

What the box changes is the tie-break, and a tie means two lines identical apart from capitals. Over 7,500 pairs of real words:

PairsTestedOrder changes
differing only by case 3,000 50%
every other pair 4,500 0

Not "rarely" — never. On 4,500 pairs of genuinely different words the box made no difference at all. Its whole effect is deciding whether Apple or apple comes first, and only in the half of cases where the capitalised form was typed first, because a stable sort leaves the rest where they are.

Result
as typedApple | apple | BANANA | banana | Cherry
box offapple | Apple | banana | BANANA | Cherry
box onApple | apple | BANANA | banana | Cherry

And it does not touch deduplication at all

Removing duplicates compares lines exactly, always. Running it on the same list leaves all 5 lines standing whether the box is ticked or not — "Apple" and "apple" are different lines, and that does not change.

That is a defensible split. Case is often meaningful in data and rarely meaningful in alphabetising, so the two operations reasonably want different rules. But the checkbox sits above both buttons and reads like it governs both, when it governs a tie-break in one of them. If you need case-insensitive deduplication, lower-case the list first and then remove duplicates.

One thing that behaves exactly as you would hope: the sort is stable, so lines the comparison considers equal keep the order they arrived in. Sorting bravo, Bravo, BRAVO, alpha with case ignored gives alpha, bravo, Bravo, BRAVO — the three tied entries untouched, rather than shuffled arbitrarily. JavaScript has guaranteed that since 2019; before then it was up to the browser.

How to use

  1. Paste your list, one item per line.
  2. Choose a sort order.
  3. Toggle case sensitivity and natural sorting as needed.
  4. Copy the result.

Frequently asked questions

Why does item10 sort before item2?

Because plain alphabetical sorting compares character by character, and the character 1 comes before 2. Natural sorting recognises the digits as a number and orders them as you would expect. It is the difference between how a computer reads a string and how a person does.

Does case affect the order?

Yes, in a case-sensitive sort. Uppercase letters have lower character codes than lowercase, so all capitalised items sort before all lowercase ones — putting Zebra before apple. A case-insensitive sort compares them as if all one case, which is usually what people expect.

How are accented characters sorted?

It depends on the collation. A simple sort by character code puts accented letters after all unaccented ones, which is wrong in every language that uses them. A locale-aware sort places them correctly, and correct differs by language — in Swedish, some accented vowels sort after Z entirely.

What does removing duplicates keep?

The first occurrence of each line, discarding later ones. Whether two lines count as duplicates depends on your case and whitespace settings — lines differing only in trailing spaces are usually meant to be duplicates and will not be treated as such unless you trim first.

How does numeric sorting differ?

It parses each line as a number and orders by value, so 9 comes before 10 and negatives come before positives. Lines that are not numbers have to go somewhere, usually grouped at one end. Mixed content is where numeric sorting produces surprises.

Is the shuffle genuinely random?

It uses a proper shuffle algorithm giving every ordering equal probability, seeded from the browser's random number generator. That is fine for picking names or randomising a list. It is not suitable for anything where the outcome must be cryptographically unpredictable.

🔒 This tool runs entirely in your browser. Nothing you enter is uploaded, logged, or stored.