Sort Lines
Sort a list alphabetically, numerically, by line length, or reverse it entirely. Natural sort orders “item 10” after “item 9” instead of before it, which is what you usually want for filenames and versions.
How Sort Lines works
Paste the lines you want to reorder.
Pick a sort mode and direction.
Toggle case sensitivity or natural ordering as needed.
Copy the sorted list.
When to use Sort Lines
- Alphabetising a glossary, a list of names, or a set of imports so any one entry is easy to find.
- Ordering filenames or version tags like “v2” and “v10” by their embedded number instead of character by character.
- Sorting a numeric column — prices, scores, line counts — from smallest to largest by its leading value.
- Grouping lines by length to bring the shortest or the longest entries to the top.
- Reversing an already-sorted list, or shuffling lines into a random order for sampling.
- Putting a pasted list into a stable, predictable order before you diff it against another version.
Examples
Input
file2 file10 file1
Output
file1 file2 file10
Natural ordering reads the embedded numbers by value, so file10 lands after file2. A plain alphabetical sort would place file10 second, because the character “1” precedes “2”.
Input
9 80 7
Output
7 9 80
Values sort by magnitude, and the blank line is collected and appended after the sorted content rather than left mid-list.
How Sort Lines works under the hood
The text is first split into lines with line endings normalised, then partitioned: lines with visible content are sorted, and blank lines — those that are empty or hold only whitespace — are set aside and appended after the sorted block, whatever the mode or direction. That keeps a stray empty line from landing in the middle of an otherwise clean list. To drop blanks entirely rather than park them at the end, run Remove Empty Lines first.
Alphabetical mode compares text with the browser’s own Intl.Collator, which orders letters the way a locale expects rather than by raw byte value. Natural order, when on, uses a numeric-aware collator so a run of digits inside a line is compared by value — “item 9” before “item 10” — which is what you almost always want for filenames and versions. Natural order compares case-insensitively; the separate case-sensitive toggle applies only to a plain alphabetical sort and is disabled while natural order is on.
Numeric mode reads the first number it finds in each line — an optional sign, digits, and an optional decimal part — and orders by that value. Lines that contain no number are treated as unsortable and pushed to the end, so a mixed column does not error out. Length mode sorts by character count, breaking ties with the same text comparison, and reverse simply flips the current order while random performs a Fisher–Yates shuffle for an unbiased reordering.
The underlying sort is stable, so lines that compare equal keep their original relative order — the one exception being random mode, which is meant to reorder them. Ascending and descending are handled by reversing the sorted content for the descending case; the descending toggle is switched off for reverse and random, where a direction has no meaning. Everything runs locally through the browser’s collator, so your list is never sent to a server.
Common mistakes
- Leaving natural order on when you genuinely want strict alphabetical ordering. Natural order groups digit runs by value and ignores case, which changes both where numbered entries land and how capitals are ordered.
- Expecting numeric mode to sort by a number that is not first in the line. It reads the first number it finds, so “ticket 12 (2024)” sorts on 12, not 2024; rearrange the field order if you need to sort on a later value.
- Assuming blank lines are removed. They are moved to the end and reported in the summary, not deleted — clear them with Remove Empty Lines beforehand if you want them gone.
- Wondering why the case-sensitive toggle does nothing. It only affects a plain alphabetical sort and is disabled while natural order is on, because natural ordering compares without regard to case.