Skip to content
ZeroServer.tools

Sort Lines Alphabetically

Sort lines A–Z or Z–A, with case and duplicate options.

Original Lines: 0Final Lines: 0

Sorting Lines the Way You Expect

Lines are sorted with a locale-aware collator, so accented characters file next to their base letter — Ápple sits beside apple rather than being exiled to the end the way a raw byte comparison would put it. By default the sort is case-insensitive (A and a group together); enable case sensitive to make every difference count, including case and accents. You can reverse the order to Z–A and optionally strip duplicate lines in the same pass. All sorting happens locally and instantly.

Turn on natural (numeric) order when your lines contain numbers. Plain alphabetical comparison reads digits one character at a time, so item10 comes before item2 — correct for text, almost never what you wanted. Natural order compares the numbers by value, giving item1, item2, item3, item10, item20. It is the right setting for filenames, version fragments and anything numbered.

Built and maintained by Meet Shah · Last updated

What this tool is used for

  • Alphabetising a list before deduplicating or reviewing it.
  • Sorting entries so two lists can be diffed meaningfully.
  • Ordering a glossary so a reader can find a term without searching.
  • Sorting a list descending to see the last entries first.
  • Preparing a list for a format that expects sorted input.

Frequently Asked Questions

How does the sort handle case?
It depends on the mode. A plain code-unit sort puts every uppercase letter before every lowercase one, so `Zebra` precedes `apple`. A case-insensitive sort is usually what people mean by alphabetical, and the difference is startling on a mixed-case list.
Why do numbers sort strangely?
Because they are compared as text, character by character — so `10` comes before `2`, since `1` is less than `2`. A natural sort compares embedded digit runs numerically and fixes it, which is what file managers do and what a plain sort does not.
What about accented characters?
A code-unit sort puts them after Z, because their code points are higher — so `Zoe` precedes `Émile`. Locale-aware collation through `Intl.Collator` places them where a dictionary in that language would, which differs by language for the same characters.
Does it remove duplicate lines?
Only if you ask it to. Sorting groups duplicates together, which is what makes them easy to spot, but removing them is a separate decision — sometimes the repetition is the data. Deduplication after sorting compares exact text, including trailing whitespace.
What happens to blank lines?
They sort to the top, since an empty string precedes everything. That is usually noise rather than information, so stripping them first is common — and it is worth checking whether your "blank" lines contain spaces, which sort differently from truly empty ones.

Common errors and gotchas

  • Choosing Z-A and forgetting it reverses the collation rather than reversing the sorted list.
  • Using an ASCII comparison on non-English text, which misplaces accented characters.
  • Sorting case-sensitively without meaning to, which clusters capitals separately.
  • Sorting a file whose first line was a header, which lands in the middle.
  • Sorting case-sensitively so every capitalised entry lands before every lower-case one.

Related Text Tools tools

Private & free — this tool runs entirely in your browser.