Skip to content
TextRuns in your browser

Sort Lines

Sort a list alphabetically, numerically, by length or into reverse order.

Input
No upload needed — instant
Privacy
Nothing is uploaded
Cost
Free · no sign-up · no watermark

Loading tool…

The tool is loading its code on your device. This happens once and is cached for later visits.

Processed entirely on your device

Everything you type or paste is handled by JavaScript running in this tab. No request is sent, nothing is logged and nothing is stored. Close the page and it is gone.

Overview

About the Sort Lines

Sort lines of text online: A–Z, Z–A, natural numeric order, shortest first, by length, or shuffle. Deduplicate while sorting and copy the result instantly.

Sorting a list is easy until the list contains numbers. Then every naive implementation produces 1, 10, 100, 2, 20, 3 and you spend ten minutes working out why. The distinction between lexicographic and natural ordering is the single most useful thing to understand about sorting text.

Lexicographic versus natural

Lexicographic sorting compares character by character using code-point order. It is fast, deterministic and completely wrong for anything containing digits, because it compares the characters 1 and 2 rather than the numbers 10 and 2.

Natural sorting tokenises each line into runs of digits and runs of non-digits, compares the non-digit runs lexicographically and the digit runs numerically. img2.png and img10.png share the prefix img, then 2 and 10 are compared as numbers, giving the order a human expects.

Which mode to choose

Your dataMode
Names, words, tagsAlphabetical
Pure numbers, prices, scoresNumeric
File names, versions, chaptersNatural
Finding outliers in a listBy length
Randomising a draw or sampleShuffle
Flipping an existing orderReverse

Case sensitivity

Case-insensitive sorting is what people almost always mean. It treats apple and Apple as equal and orders by the letters themselves. Case-sensitive ASCII sorting puts all uppercase before all lowercase, producing Zebra, apple, banana — occasionally useful for matching a specific system's behaviour, usually just confusing.

When two lines compare as equal under case-insensitive sorting, this tool falls back to a case-sensitive comparison so the order remains stable and reproducible rather than depending on the input arrangement.

Sorting stability

A stable sort preserves the relative order of items that compare equal. JavaScript's Array.prototype.sort has been guaranteed stable since ES2019, so equal lines keep their input order. That matters when you sort a list of surname, firstname pairs by surname and expect ties to remain in their original sequence.

Combining operations

The dedupe and blank-line toggles run before sorting, which is the efficient order: fewer items to compare, and no empty lines cluttering the top of the result. For deeper cleaning — trimming internal whitespace, stripping punctuation — run the text through a cleaner first, then sort.

Step by step

How to use the Sort Lines

  1. Paste the list you want to sort, one item per line.

  2. Pick a sort mode: alphabetical, numeric, natural, by length, or random shuffle.

  3. Choose ascending or descending, and toggle case-sensitivity if it matters.

  4. Optionally remove duplicates and blank lines in the same pass.

  5. Press Sort and copy or download the ordered list.

Why use it

Benefits and common use cases

What this tool is good for, and what it deliberately does not try to do.

Natural sort that understands numbers

item2 comes before item10, not after — the classic lexicographic sorting bug that ruins file lists, version numbers and chapter orders.

Numeric sorting for real data

Sorts lines that are pure numbers by value, so 100 lands after 99 rather than between 10 and 11.

Length and reverse modes

Order by character count to find outliers, or reverse an existing order without re-sorting from scratch.

Dedupe in the same pass

Sorting and duplicate removal together is the most common combination, so it is one toggle rather than two trips to two tools.

Questions

Frequently asked questions

Short, honest answers about quality, limits and privacy.

What is natural sort?

Natural sort compares embedded numbers by value instead of digit by digit. Standard alphabetical sort puts item10 before item2 because '1' sorts before '2'; natural sort correctly orders item1, item2, item10. It is what file explorers and version lists use.

Is sorting case-sensitive?

By default it is case-insensitive, so apple and Apple sort together. Enable case-sensitive mode and uppercase letters sort before lowercase, matching the behaviour of ASCII ordering and most programming-language default sorts.

How are blank lines handled?

They sort to the top in ascending order because an empty string compares less than everything. Toggle blank-line removal to drop them entirely, which is usually what you want for a clean list.

Can I sort numbers with commas or units?

Numeric mode parses leading numeric content and ignores thousands separators, so 1,250 and 1250 sort identically. Values with trailing units like '12 kg' are compared by their leading number. Mixed text and numbers are best handled with natural sort.

Is the shuffle truly random?

It uses a Fisher–Yates shuffle over the browser's cryptographic random source, so every permutation is equally likely and the order is not reproducible — which is the point when you are randomising a draw or a sample.