Line Sorter

Share:

Sort lines alphabetically, naturally (file9 before file10), by length, or shuffle — with optional dedupe, trim, reverse.

RT-TXT-020 · Text Tools

Line Sorter Tool

Advertisement
After results · AD-W1 Responsive · Post-tool — peak engagement

How to use the line sorter

Paste your lines

One item per line in the left textarea. Anything works — file names, email addresses, log entries, code identifiers.

Pick a sort mode

Natural sorts numbers like a human (file2 before file10). Alphabetical is the strict character-order sort. Length orders shortest-to-longest. Shuffle randomises.

Toggle the options

Dedupe removes duplicates (case-insensitive if that option is also on). Trim strips leading/trailing whitespace. Reverse flips the final order. Keep blanks preserves empty lines.

Copy, download, or chain

Use the copy / download buttons for the result, or click Output → Input to pipe the sorted lines back through another transform (e.g. sort, then dedupe, then shuffle).

Advertisement
After how-to · AD-W2 Responsive

Sorting lines — alphabetical vs natural vs length

Sorting a list of lines sounds trivial — alphabetical means A before B, right? It does, except when your list contains numbers, mixed cases, or human-meaningful patterns. file1.txt, file2.txt, file10.txt alphabetically becomes file1.txt, file10.txt, file2.txt because "1" < "2" character-wise. That's correct by the rules of lexicographic comparison and almost never what you want. Natural sort — treating runs of digits as numbers — produces the intuitive ordering and is the right default for filenames, version numbers, and most human-curated lists.

When to use each mode

Alphabetical (strict lexicographic) is right when you have no embedded numbers and care about exact character order — e.g. a list of names, words, slugs, or labels. Natural is right when your lines contain numbers that should sort numerically — file paths, version tags, sortable identifiers, episode titles. Length is right when you're spotting outliers — the longest URL in a log, the shortest acceptable password from a generated list, the most concise variant of a wording. Shuffle is right when you want randomised order — e.g. randomising a list of names for a draw, picking a non-obvious anonymisation order, generating a randomised test order.

The dedupe option is more useful than it looks

A surprising amount of real-world list work is "deduplicate this thing" — extracted email addresses, log paths, queried identifiers, URLs from a crawl. The tool's dedupe pass is exact-match (line-by-line) and respects the case-insensitive toggle, so [email protected] and [email protected] collapse to one entry when CI is on. For more sophisticated email-deduplication (Gmail dot variants, plus-tag aliases), use the dedicated Email Normalizer tool.

ASEAN-specific quirks

Localised sort orders matter when handling Asian-language content. Singaporean and Malaysian English content sorts the same as global English — straightforward. Indonesian and Filipino content is similar but watch for embedded diacritics (café should sort with cafe, which JavaScript's localeCompare() handles by default in this tool). Chinese characters sort by Unicode code-point order, which roughly tracks frequency of use — not pinyin-alphabetical, not stroke-count. If you need pinyin sort, pre-convert via the Chinese Converter first.

Why shuffle uses crypto.getRandomValues

The shuffle mode runs Fisher-Yates with window.crypto.getRandomValues() as the entropy source, so the resulting order is statistically uniform across all possible permutations — no clock-seeded predictability. For a list of 100 items, that's 100! ≈ 10^158 possible orderings. Math.random()-based shuffles can only reach a few billion of those (limited by the PRNG's internal state), which sometimes matters for cryptographic-grade randomness. For everyday list shuffling, the difference is invisible; we use the secure source anyway because it's the right default.

Composing operations with Output → Input

The Output → Input button enables piping the result back through another transform. Common chains: sort first, then dedupe to eliminate adjacent duplicates and rerun stats. Or: sort length-first, output the longest 10 manually, paste back, then alphabetise. The chaining cost is one button click and no re-paste — useful when you're building a list iteratively. Power users sometimes treat the tool as a personal data-cleaning pipeline: trim, then dedupe, then natural-sort, then output to a final destination. Each step is reversible (the input textarea keeps its previous value until you click Output → Input).

10 facts about sorting

01

Natural sort was popularised by Mac OS X's Finder in 2001. Before that, "file10.txt" really did come before "file2.txt" in most file managers.

02

JavaScript's localeCompare(undefined, {numeric: true}) gives natural sort for free — but you have to remember the second-argument options object.

03

The fastest comparison sort possible is O(n log n). Heapsort, mergesort, and most quicksort variants achieve this. Counting sort beats it for integer keys.

04

Fisher-Yates shuffle (1938) is the only correct way to shuffle an array. Common alternatives (sort(() => Math.random() - 0.5)) are biased and broken.

05

The 1947 UNIVAC I sorted census data using a merge sort over magnetic tapes — the original "external sort" algorithm. Hadoop and modern map-reduce still use the same pattern.

06

Timsort — invented by Tim Peters for Python in 2002, now the standard sort in JavaScript V8 and Java — combines merge sort and insertion sort for real-world data with partial existing order.

07

Bubble sort is named after the way large elements "bubble up" to the end of the list. It's O(n²) and almost always the wrong choice. Used only for teaching.

08

Stable sort means equal elements preserve their relative input order. Array.prototype.sort() in JS has been stable since ES2019; before that, behaviour varied by engine.

09

The Singapore Civic District uses ICAO-style alphabetical road sort in its address database, not natural — so "Bukit Timah Road 10" sorts before "Bukit Timah Road 2".

10

The largest list ever sorted in a single benchmark was 100 trillion entries (10 PB) by Google in 2021, using their Borg cluster. Took about 30 minutes.

Frequently asked questions

Sort that treats embedded numbers as numbers. file2.txt comes before file10.txt instead of after. Use it for filenames, version tags, episode titles — anything where humans would expect numeric order.
Yes, line-by-line. Case-insensitive if you also tick that option. For email-specific dedupe (Gmail dot variants, +tag aliases), use the Email Normalizer tool instead.
Either trim+blank removed empty lines, or dedupe collapsed duplicates. The stats row below the buttons shows "X input → Y output (Z removed)" so you can confirm.
Tested up to 1 million lines (~30 MB text). The sort itself is fast; the textarea rendering is the bottleneck above a few hundred thousand lines.
Yes — pick "No sort" to apply just the other operations (dedupe, trim, reverse) without re-ordering.
Fisher-Yates needs unbiased random indices to produce uniform permutations. Math.random() gives statistically random but predictable values; crypto.getRandomValues gives unguessable ones. For non-trivial shuffles (lottery draws, anonymisation orderings), the difference matters.
Not currently — sorting treats each line as one unit. For tabular sort with column awareness, pipe through a spreadsheet or use jq for JSON.
localeCompare() handles diacritic-equivalent characters (café vs cafe) correctly for the alphabetical and natural modes. NFKD-style canonicalisation is not applied; if you need it, normalise upstream.
No. All sorting happens inside your browser. Paste sensitive lists with confidence — they never leave your machine.
Lines with the same length fall back to alphabetical ordering (case-insensitive if that option is on). Stable behaviour — identical lines preserve input order.

Related News

You may be interested in these recent stories from our newsroom.

View all news →
Advertisement
Pre-footer · AD-W3 728 × 90

75 more free tools

Calculators, converters, security tools — no signup.