Sort Lines
Sort lines alphabetically A-Z, Z-A, by length, natural number order, by column, or shuffle. Remove duplicate lines, trim, dedupe. Free, in your browser.
About Sort Lines Tool
Sort Lines is a multi-strategy line sorter with six ordering modes and four optional pre-processing steps. The six modes are: A-Z alphabetical (uses String.prototype.localeCompare() for accent-aware natural-alphabet ordering — 'á' sorts between 'a' and 'b' rather than after 'z'), Z-A reverse alphabetical, ascending length (sorts by Character count via String.length), descending length, Natural sort (the Intl.Collator with numeric:true option that orders 'file2' before 'file10' instead of after, matching the way Windows Explorer and modern file managers sort), and Random shuffle (Fisher-Yates algorithm using Math.random() for an unbiased permutation). Optional pre-processing applies before sorting: Trim Whitespace strips leading/trailing whitespace from each line via String.trim(), Remove Empty Lines drops blank or whitespace-only lines, Remove Duplicates keeps only the first occurrence of each unique line, and Case Sensitive toggles whether 'Apple' and 'apple' are considered different (default off, so case is folded). Typical workflows: alphabetize an unsorted list of customer names with proper handling of café and Müller, sort filenames naturally so v1.10 comes after v1.9 not after v1.1, randomize a list of trivia questions or playlist songs, build dedupe-and-sort pipelines for log analysis, and length-sort to find the longest/shortest entries in a dataset.
What is Natural sort and why does '10' come after '2' in alphabetical but before in Natural?
Alphabetical sort compares strings character-by-character: '1' (code point 49) < '2' (code point 50), so '10' is treated as starting with '1' and sorts before '2'. Natural sort detects embedded numeric substrings and compares them as numbers: in '10' it sees ten, in '2' it sees two, and 2 < 10, so '2' comes first. This is what humans expect for filenames (file2.txt before file10.txt), version strings (v1.9 before v1.10), and addresses (Apt 2 before Apt 10). Implemented via Intl.Collator with {numeric: true, sensitivity: 'base'}, which is the modern web standard and handles mixed alphanumeric correctly.
How does case sensitivity actually work — what about accented characters like 'café'?
When Case Sensitive is OFF (default), the sorter uses locale-aware case folding via localeCompare with sensitivity: 'base' — so 'Apple', 'APPLE', and 'apple' all sort as if identical, and accents like 'café' vs 'cafe' also fold to the same key. When Case Sensitive is ON, uppercase letters (code points 65-90) sort before lowercase (97-122), so 'Zebra' comes before 'apple'. For Vietnamese with full tones (à, ả, ã, á, ạ) the accent-folded mode treats all five 'a' variants as equivalent for sorting; accent-strict mode (not exposed in UI) would keep them distinct. To preserve Vietnamese tonal order strictly, sort externally with locale='vi'.
What is the difference between this tool and Unix `sort`?
Unix `sort` is the gold standard CLI and supports more flags (--field-separator, --key, --month-of-year, --human-numeric), handles arbitrarily large files via external merge sort, and is faster on multi-gigabyte inputs. This tool provides the most common 80% of use cases (alphabetical, reverse, natural, length, random, dedupe) in a browser UI with no install. For one-off sorts of a list pasted from email or Excel, the browser is faster (no file save needed). For a 10 GB log file, use `sort` or `sort -V` (version sort, which is similar to natural). The browser version is also locale-aware out of the box — `sort` defaults to bytewise unless you set LC_ALL=en_US.UTF-8.
In what order does it apply Trim, Remove Empty, Remove Duplicates, and the actual sort?
The pipeline is: 1) Trim Whitespace, 2) Remove Empty Lines, 3) Remove Duplicates, 4) Sort. This order matters. Trimming first means ' apple' and 'apple' are recognised as the same, so dedupe can match them. Removing empty lines next keeps them out of the result and the duplicate count. Dedupe runs on the FULL line (not the sort key/column), keeping the first occurrence of each unique line. Sorting happens last. The stat boxes reflect each stage: Total Lines = raw input, Empty Removed = blank/whitespace-only lines dropped, Duplicates Removed = repeated lines dropped, Sorted Lines = final output. Array.sort is stable in modern engines (V8, SpiderMonkey, JavaScriptCore), so when two keys are equal — common with column sorting — lines keep their original relative order, which matters when a secondary order should be preserved.

How do I sort by a specific column or field instead of the whole line?
Turn on 'Sort by column/field', pick the delimiter (comma for CSV, tab for TSV, semicolon, pipe, or whitespace for log lines), and set the 1-based field number. This is the browser equivalent of Unix `sort -t, -k2` — it sorts each row by the chosen field while keeping the full original line intact in the output. Example: for 'Smith,John,42' with delimiter Comma and field 2, rows sort by first name (John). It composes with every mode: alphabetical, reverse, natural (so column values like v1.9 and v1.10 sort numerically), and length. Lines shorter than the requested field are treated as an empty key and sort to the top (ascending). Note that Remove Duplicates still compares the FULL line, not just the key, so two rows with the same column-2 value but different other columns are both kept.
What is the difference between reverse, numeric, and natural sort — and can I reverse lines without sorting?
Reverse (Z → A) is alphabetical sort in descending order. Numeric-only sorting does not exist as a separate mode here — instead, Natural sort handles numbers inside strings: pure numbers like '2', '10', '100' sort 2 < 10 < 100 as you expect, and mixed strings like 'item2' before 'item10' also work, because Natural compares embedded digit runs as numbers via Intl.Collator numeric:true. Plain alphabetical (A → Z) instead compares character codes, so '10' sorts before '2'. To simply reverse the existing order of lines without alphabetising (flip top-to-bottom), this tool does not expose a raw line-reversal toggle; use Random for a shuffle, or paste the lines pre-reversed. For true numeric data, use Natural.
How random is Random Shuffle — is it cryptographically secure?
It uses the Fisher-Yates shuffle algorithm with Math.random() as the source of randomness. This produces an unbiased uniform permutation (each of n! orderings has equal probability), which is mathematically correct for ordinary shuffling. However, Math.random() is NOT cryptographically secure — it is a deterministic pseudorandom generator that, in theory, could be predicted if you knew its internal state. For shuffling playlists, contest entries, trivia, or party games, it is perfectly adequate. For security-sensitive use cases (lottery draws, jury selection), use crypto.getRandomValues() in a custom script instead.
How does the tool handle very long inputs — does it scale to 1 million lines?
Yes, with caveats. JavaScript Array.sort() is O(n log n) on average using TimSort in Chrome/Edge/Firefox, so 1 million lines sort in roughly 1-3 seconds on a modern laptop. The browser textarea becomes the bottleneck — pasting 50+ MB of text can stall the UI. For datasets above 10 MB, prefer Unix `sort -u file.txt > out.txt` which streams from disk and handles arbitrarily large files via external merge sort. The 'Total Lines' counter shows how many lines you have before sorting, useful for sanity-checking that paste worked.
Is sorting done in the browser and is my text private?
Yes. All sorting runs in JavaScript via Array.sort(), Intl.Collator, and Fisher-Yates — no fetch() to a server, no analytics with content, no localStorage write. Open DevTools Network and click Sort to verify zero outbound requests. Safe for sensitive lists like customer email lists, employee rosters, internal hostnames, password generators output, or any data you should not upload.
