Sort Lines Alphabetically
Sort a list of lines A–Z, Z–A, naturally, by number or by length.
Results are provided as is, for general information. Check anything important before relying on it. See the Terms of Use.
About this tool
Sort lines of text four ways: alphabetically (locale-aware, so accented letters sort with their base letter), naturally (digit runs compare as numbers, so file2 comes before file10), by the number each line starts with, or by line length. Each can be reversed, and case sensitivity and blank-line removal are optional. The sort is stable: lines that compare equal keep their original order. In numeric mode, lines with no leading number always go to the end, whichever direction you choose.
When to use it
Questions
What is the difference between alphabetical and natural sort?
Alphabetical compares character by character, so file10 sorts before file2 because '1' comes before '2'. Natural sort reads digit runs as whole numbers, so file2 comes before file10. Use natural for filenames and version-like labels.
How does numeric sort treat lines without a number?
It uses the number a line starts with, including a minus sign or decimal point, and places lines with no leading number at the end, in their original order. That holds for ascending and descending.
Is sorting case sensitive?
Not by default: 'banana' and 'Banana' compare as equal and keep their original order. Turn case sensitivity on to separate them; lowercase then sorts before the matching uppercase.
Does it remove duplicates?
No. Use Remove Duplicate Lines for that. Running the two tools in either order gives a sorted, unique list.
Why does file10 sort before file2?
Alphabetical mode compares character by character, and '1' precedes '2' — so file10 lands first. Natural mode reads digit runs as numbers and orders file2, then file10; it is the mode for filenames, version-like labels and numbered headings, and it fixes the ordering deeper into lines too (v1.10 after v1.9). Alphabetical remains the right choice for word lists, where digit runs should not get number semantics.
How does numeric mode handle lines without a leading number?
They always go to the end, whichever direction you sort — a fixed rule so non-numeric entries stay visible at a predictable edge instead of scattering through the middle. The number used is the line's leading number (signs and decimal points count), so '3 apples' sorts as 3; ties on that number fall back to original order, because the sort is stable.
Why does stability matter in a sort tool?
Stability — equal lines keep their original relative order — is what makes two-pass sorting possible: sort by the secondary key first, then by the primary, and the secondary order survives within each primary group. An unstable sort would silently destroy that first pass and leave you an order you cannot reproduce. This tool guarantees stability in every mode, including the numeric no-number-at-the-end rule.
What does case sensitivity change?
By default, case is ignored: 'banana' and 'Banana' compare equal and keep original order. Enabled, every character counts and capitals sort strictly before their lowercase counterparts — 'Banana' then 'banana' — giving mixed-case identifier lists a deterministic strict order. For human-readable lists the default is almost always right; case sensitivity is for code-style lists where that strictness is the requirement.
Does sorting deduplicate or drop blanks?
Blank-line removal is an option (off by default); duplicate removal is not, deliberately — silently merging repeated lines would corrupt data where repeats are legitimate. When you want both, the pipeline is this tool plus Remove Duplicate Lines, in either order: sort-then-dedupe if you want to see the repeats before collapsing, dedupe-then-sort for a one-way cleanup.
How is line length measured?
In Unicode code points — the same count the word-count tools use, so an emoji counts as one and accented letters as one, not two. It is a pure, machine-independent count, so length order is reproducible everywhere; alphabetical order, by comparison, follows locale collation rules, which is a subtly different thing to reason about across machines.