Sort Lines
Sort text lines alphabetically, numerically, by length, or shuffle them. Handles lists, keywords, and CSV columns instantly.
Sort any list of lines alphabetically, numerically, by length, in reverse, or shuffled — with case-insensitive comparison on by default so "apple" and "Apple" sort together, and numeric mode that reads the first number in each line instead of sorting "10" before "2".
How to use Sort Lines
- Paste the lines.
- Pick a sort mode and whether to drop empty lines or ignore case.
- Copy the sorted result.
Who it is for
Developers sorting import lists and config keys, teachers randomising student names, editors alphabetising reference lists, and anyone whose spreadsheet export came out unsorted.
How it works
- Alphabetical sorting uses locale-aware case-insensitive comparison; numeric mode extracts the first number per line and sorts by value, sinking number-less lines to the bottom.
- Length modes sort shortest or longest first with an alphabetical tiebreak; shuffle uses a Fisher–Yates pass for a fair random order.
- Empty lines can be dropped in the same pass, and output updates live.
What it cannot do
- Numeric mode looks at the first number only — "room 12 block 3" sorts as 12.
- Locale collation follows your browser’s locale, so accented sorts can differ slightly between machines.
Sample input & output
invoice-104.pdf invoice-9.pdf invoice-22.pdf summary.pdf
Numeric sort: invoice-9.pdf, invoice-22.pdf, invoice-104.pdf, summary.pdf (ordered by extracted numeric value 9 < 22 < 104, with non-numeric lines placed last).
Frequently asked questions
Why did "10" sort before "2" in alphabetical mode?
Alphabetical comparison is character by character, and "1" comes before "2". Switch to Numeric mode when the lines start with numbers.
Is the shuffle fair?
It is a Fisher–Yates shuffle over crypto-quality randomness in your browser — every order is equally likely.
Can it sort by column, like a spreadsheet?
Not directly. Lines are atomic. Extract the column first, sort it, and paste it back.
What is the difference between ASCII code-point order and locale-aware alphabetical sorting?
Raw ASCII code-point sorting (JavaScript's bare Array.prototype.sort()) ranks every uppercase letter 'A'–'Z' (codes 65–90) ahead of lowercase 'a' (code 97) and pushes accented letters like 'É' (code 201) after 'z'. Locale-aware collation via String.prototype.localeCompare groups 'a', 'A', and accented variants in dictionary order so human-facing glossaries, bibliography entries, and name rosters sort the way readers expect.
How does Fisher-Yates shuffling guarantee an unbiased random line order?
Naive shuffles such as array.sort(() => Math.random() - 0.5) violate comparator transitivity in engine quicksort/Timsort implementations, heavily biasing elements toward their starting positions. The Durstenfeld Fisher-Yates algorithm walks backward from index n - 1 down to 1, swapping each line once with a uniformly chosen index in 0..i, giving all n! possible permutations an equal mathematical probability in O(n) time.
How does numeric mode handle negative numbers, decimals, and mixed text prefixes?
Numeric mode scans each line for its first signed integer or decimal number — matching patterns like -12.5, 0.75, or the 104 inside "invoice-104.pdf" — and compares those parsed floating-point values directly so -10 precedes -2, which precedes 0 and 9.5. Lines containing no digits at all cannot be coerced to zero without mixing into signed data, so they group cleanly at the bottom.
When is sorting lines by character length useful in engineering and SEO workflows?
Shortest-first and longest-first length sorting immediately surfaces outliers in structured datasets: finding meta titles exceeding 60 characters in a URL export, prioritizing terse seed keywords ahead of long-tail phrases, auditing variable-length CSV rows corrupted by missing delimiters, or ordering regex alternation branches longest-first (for example, "foobar|foo") so an engine does not prematurely stop on a shorter prefix.