Skip to main content
LS

Line Sorter

Sort, reverse or shuffle a list of lines — alphabetically, numerically, by length, or at random.

Did you like the tool? Thanks!
Share:

Shuffle is random, so it only runs when you click the button — not on every keystroke.


    

How to Use Line Sorter

Paste a list with one item per line and pick a sort mode: alphabetical (A→Z or Z→A), numerical (by a leading number in each line), by length, reversed, or randomly shuffled. Case-insensitive sorting and duplicate-line removal are optional toggles. Everything updates live as you type or change options, except Shuffle, which runs only when you click its button.

About Line Sorter

Sorting a list of lines by hand is tedious and error-prone the moment the list gets longer than a handful of items — a spreadsheet-imported list of names, a set of copy-pasted URLs, a to-do list, or CSV-adjacent data pasted straight from an email. This tool covers the sorting operations people reach for most often on plain-text lists, without needing to open a spreadsheet application just to sort a dozen lines. Alphabetical A→Z and Z→A sorting compares each line as text. A "case-insensitive" toggle (on by default) controls whether `Apple` and `apple` are treated as equal for ordering purposes — with it on, `apple`, `Apple` and `APPLE` sort next to each other regardless of casing; with it off, sorting falls back to strict character-code ordering, where all uppercase letters (A–Z) sort before all lowercase letters (a–z) in standard ASCII/Unicode order, which can put `Zebra` before `apple` in a way that looks surprising if you are not expecting it. Case-insensitive is the more intuitive default for everyday lists (names, tags, words), which is why it starts checked. Numerical mode looks for a leading number in each line — not necessarily at the very start of the string, but the first run of digits (optionally with a decimal point and a leading minus sign) found anywhere near the front, so both `10. Item` and `42 apples` are recognized and sorted by 10 and 42 respectively. Lines where no number can be found at all (no digits anywhere) are pushed to the end of the sorted list, and among those number-less lines, their original relative order is preserved rather than being re-sorted by any other criterion — this matters when you are sorting a mixed list like inventory counts where a few rows genuinely have no quantity yet, and you want those left in the order you originally entered them rather than scrambled. By-length mode sorts shortest line first, which is handy for eyeballing a list by how much text each line has (short tags before long descriptions, for example) — line length is measured in actual characters (using `Array.from` to iterate by Unicode code point rather than by UTF-16 code unit), so multi-byte characters like emoji or certain accented letters are counted correctly as one character each rather than being split and over-counted. Reverse simply flips the current line order top-to-bottom without applying any sorting logic — useful when a list is already in a meaningful order (chronological, priority, whatever) and you just want to view or export it backwards. Shuffle applies a Fisher-Yates shuffle, the standard unbiased algorithm for randomly permuting a list (each of the n! possible orderings is equally likely, unlike naive "sort by random comparator" approaches which are neither uniformly random nor guaranteed stable) — because a shuffle is deliberately non-deterministic, it does not run automatically as you type or toggle options the way every other mode does; it only runs when you click the dedicated Shuffle button, so you are never surprised by your list silently re-randomizing itself while you are still typing. The "remove duplicate lines after sort" toggle drops any line that is an exact repeat of an earlier line in the sorted output (respecting the case-insensitive setting for what counts as a duplicate), keeping the first occurrence and discarding the rest — applied after sorting, so which occurrence is "first" depends on the sort order you chose, not necessarily your original paste order.

Details & Tips

Sort modes: • Alphabetical A→Z / Z→A — standard lexicographic comparison, with an explicit tie-break on original position so that genuinely equal lines keep their relative input order. • Numerical — extracts the first `-?\d+(\.\d+)?` pattern found in each line as its sort key; lines with no such pattern sort after every line that has one, and ties (including all number-less lines) keep original relative order. • By length — compares the Unicode character count of each line (via `Array.from(line).length`, which correctly counts multi-byte characters like emoji as one character rather than counting UTF-16 code units). • Reverse — reverses the current line order with no comparison logic at all. • Shuffle — a Fisher-Yates (Knuth) shuffle: iterate from the last index down to 1, and at each step swap the current element with a uniformly random earlier-or-equal element. This produces every possible ordering with equal probability, unlike sorting by `Math.random() - 0.5` in a comparator, which is a common but statistically biased anti-pattern. Why Shuffle needs a button: every other mode is a pure function of the current input and options, so it is safe to recompute automatically on every keystroke. Shuffle is intentionally random, so recomputing it automatically on every keystroke would make the list jump around unpredictably while you are still typing — it only re-runs when you explicitly click Shuffle. Duplicate removal: applied after sorting, using either exact-match or lowercased-match comparison depending on the case-insensitive toggle, keeping the first line with a given key and dropping subsequent repeats. Worked example (Numerical mode): input `10. Cherry`, `Banana`, `2 apples`, `bread` → leading numbers found: 10, none, 2, none → sorted: `2 apples`, `10. Cherry`, then the two number-less lines in their original relative order: `Banana`, `bread`. Line splitting handles Windows (`\r\n`), classic Mac (`\r`) and Unix (`\n`) line endings, so pasted content from any source is split correctly.

Frequently Asked Questions

How does Numerical sort mode work if my lines don't start with a digit?
It looks for the first run of digits anywhere near the start of each line, not only at position zero, so lines like "10. Item" or "42 apples" are both recognized and sorted by 10 and 42 respectively.
What happens to lines with no number in Numerical mode?
They are placed after every line that has a parseable number, and among themselves they keep their original relative order rather than being re-sorted by any other rule.
Why is case-insensitive sorting on by default?
Most everyday lists (names, tags, words) read more intuitively when "Apple" and "apple" sort next to each other. Turning the option off falls back to strict character-code order, which sorts all uppercase letters before all lowercase letters.
Why doesn't Shuffle update live like the other modes?
Shuffle is deliberately random, so recomputing it automatically on every keystroke would make your list jump around unpredictably while you are still editing it. It only runs when you click the Shuffle button.
Is the shuffle truly random, or biased toward certain orders?
It uses a Fisher-Yates shuffle, the standard algorithm that gives every possible ordering an equal probability of occurring — unlike a naive "sort with a random comparator" approach, which is a common but statistically biased shortcut.
What does "By length" sort by exactly?
The number of characters in each line, shortest first. Multi-character emoji and accented letters are counted correctly as single characters rather than being over-counted.
Does removing duplicates happen before or after sorting?
After sorting. The first occurrence of a duplicate (in sorted order, not your original paste order) is kept and later repeats are dropped.
Are duplicates matched case-insensitively too?
Yes, duplicate detection respects the case-insensitive toggle — with it on, "Apple" and "apple" count as the same line for deduplication purposes; with it off, they are treated as different lines.
Does Reverse sort my list first?
No, Reverse applies no sorting logic at all — it simply flips the current line order top-to-bottom, whatever that order currently is.
Can I paste a list copied from Excel or Windows Notepad?
Yes, line breaks from Windows (\r\n), old Mac (\r) and Unix/Mac (\n) sources are all recognized and split correctly.
Is there a limit to how many lines I can sort?
There is no hard-coded limit; the sorting itself is fast even for large lists since it uses the browser's native array sort, though extremely large pastes (tens of thousands of lines) may take a brief moment to render in the result box.
Is my list uploaded to a server?
No, all sorting, filtering and shuffling happens locally in your browser using JavaScript.

Part of These Collections

Also Available As

line sorter, sort lines alphabetically, sort text lines, alphabetize list online, shuffle lines, sort lines by number, remove duplicate lines

Found a Problem?

Let us know if something with Line Sorter isn't working as expected.

Thanks — we'll take a look.