Line Tools: Sort, Dedupe, Reverse, Shuffle

Paste a list — one item per line — and sort it, strip duplicates, reverse or shuffle it.

—

What this tool does

Lists arrive as blocks of text: a column copied out of a spreadsheet, a set of tags, a list of domains, a randomised draw. Cleaning them is fiddly in a text editor and awkward in a spreadsheet, and doing it by hand is how duplicates survive into a final document.

Each action here applies one well-defined transformation to the lines and leaves everything else — including blank lines — intact, so the result is predictable.

Method

ActionBehaviour
Sort A→Z / Z→ALocale-aware comparison, optionally case-insensitive by lower-casing the comparison key only (the lines themselves are never modified).
Sort by lengthAscending character count; equal lengths keep their relative order.
Remove duplicatesKeeps the first occurrence of each line and preserves the order of what remains.
ReverseReverses the order of the lines, not the characters within them.
ShuffleFisher–Yates shuffle, so every ordering is equally likely.
Number linesPrefixes each line with 1., 2. and so on, counting from one.

Line endings are handled in all three forms — LF, CRLF and CR — so a list copied from Windows behaves the same as one from a Unix system.

Example

ActionResult
Inputbanana / Apple / cherry / apple / date / banana
Sort A→Z (ignore case)Apple / apple / banana / banana / cherry / date
Remove duplicates (ignore case)banana / Apple / cherry / date
Sort by lengthdate / apple / Apple / banana / cherry / banana

Line endings are not all the same

A “line” is not a single character. Unix writes \n, Windows writes \r\n, and classic Mac OS wrote \r. A tool that splits on \n alone leaves a trailing \r on every line from a Windows file, which then shows up in comparisons, sorting and output — an invisible character at the end of every line. This tool normalises line endings before operating and writes back a consistent form.

That matters more than it sounds: sorting a Windows-origin list can put entries in the wrong order if the \r is compared, and a “remove duplicates” pass will not merge apple\r with apple.

Sorting: case, locale and stability

“Sort A→Z” hides three decisions. Whether uppercase sorts before lowercase, whether accented letters sort with their base letter, and whether equal elements keep their relative order.

ModeOrder of apple, Apple, bananaRule
Case-sensitive (byte order)Apple, apple, bananaUppercase sorts first in ASCII
Ignore caseapple, Apple, banana (stable)Compared case-insensitively, ties keep input order
By lengthapple, Apple, bananaLength first, then the same comparison

A locale-aware sort would also place é next to e rather than after z, which is what a reader expects in French but not what a byte comparison does. This tool uses the simple comparison, which is predictable and matches what a program will do.

Deduplication and whitespace

Removing duplicates compares whole lines. If one line has a trailing space and the other does not, they are different lines and both survive — which is usually not what the user wants. Trimming whitespace first, then deduplicating, is the order that gives the expected result.

“Ignore case” deduplication keeps the first occurrence of each case-insensitive match, so Apple and apple collapse to whichever came first. That is a lossy operation: if the capitalisation was meaningful, it is gone.

Where line tools are used

  • Cleaning a pasted list — removing blanks, trimming, sorting before pasting into a form or a query.
  • Preparing a SQL IN list — one quoted value per line, sorted and deduplicated.
  • Comparing two lists — sort both, then diff; the result is far easier to read than an unsorted diff.
  • Log triage — deduplicating repeated lines to see the distinct events.

What it does not do

No regular-expression filtering, no column extraction, no joining lines back into a paragraph. Each of those needs its own input (a pattern, a delimiter, a width) and is a different tool. Line tools stay deliberately line-oriented: each operation transforms the list of lines, and nothing crosses a line boundary except a join.

Frequently asked questions

Does the sort understand numbers?

No — it sorts as text using locale-aware comparison, so 10 comes before 2. For numeric order, pad the values to the same width (002, 010) before sorting, or sort in a spreadsheet with a numeric column. The tool states this rather than guessing which lines are numbers.

What can I do to the lines?

Sort A→Z, sort Z→A, sort by length, remove duplicates, reverse the order, shuffle randomly, and number the lines. Each action keeps the text otherwise unchanged.

Is sorting case-sensitive?

You choose. Case-sensitive sorting puts all upper-case lines before lower-case ones, which is the technical default; case-insensitive sorting treats Apple and apple as the same word for ordering.

Does “remove duplicates” keep the first or the last copy?

It keeps the first occurrence and drops later ones, which preserves the original order of the remaining lines.

Are blank lines preserved?

Yes. Blank lines are treated as ordinary lines, so sorting groups them together at the top and deduplication collapses them to one.

Is the shuffle repeatable?

No. It uses a random order each time you press it, which is the useful behaviour when you are drawing a random order rather than reproducing one.

Sources

  • Unicode Collation Algorithm, used through the platform’s locale-aware string comparison for sorting.
  • The Fisher–Yates shuffle, for an unbiased random ordering.

Everything runs in your browser — nothing you type is uploaded.