Sort / Dedupe Lines

How do I sort lines of text?

How it is calculated

The text is split into lines at every line break (Windows, Mac or Unix style). Three modes are available: asc sorts A to Z, desc sorts Z to A, and unique first drops repeated lines and then sorts what is left in ascending order. Any other mode value falls back to ascending. Sorting is case-insensitive and natural, so digit runs are compared as numbers (item2 comes before item10), and lines that compare equal keep their original relative order. Duplicates are matched exactly, including case and spaces. Empty lines count as lines: a blank line sorts to the top in ascending order, and a trailing line break adds one. Descending order is simply the ascending result reversed.

Worked example

Paste three lines, item10, item2 and item2, and choose the unique mode. Step 1: the second item2 is an exact repeat, so it is removed, leaving item10 and item2. Step 2: the natural sort compares the numbers 2 and 10 rather than the characters, so item2 goes first. The output is:

item2 item10

With a plain character sort, item10 would have come first, because 1 sorts before 2.

Try this example →

Common mistakes

  • Expecting duplicates that differ only in case or trailing spaces to be merged. x, X and x followed by a trailing space are three different lines, so all three survive in unique mode (a second plain x would be an exact repeat and be dropped); trim and lower-case the text first if you want them merged.
  • Leaving a blank line at the end of the pasted list. It counts as an empty line and sorts to the very top, so the output starts with an empty row.
  • Expecting unique mode to keep the original order. It always returns the unique lines sorted ascending, and the descending option does not apply together with it.
  • Assuming accented letters sort as in your language. They are placed by character code, after the plain letters, so a name starting with Ç ends up after Z.
  • Sorting a column of numbers and expecting pure numeric order. Only digit runs inside a line are read as numbers; negative signs and decimal points are treated as ordinary characters.

About this calculator

This tool takes a block of text and does one of two things with its lines: sorts them in ascending (A→Z) or descending (Z→A) order, or removes duplicate lines and returns what is left in ascending order. The sort treats A–Z and a–z as equivalent and reads digit runs as numbers, so item9 comes before item10; everything else is compared by character code, which puts accented letters after the unaccented ones rather than where your language would. The duplicate test is stricter: repeats have to match exactly, so a difference in case counts as two lines and both are kept. Either way the tool works line by line on the text itself, not on what the content means — a simple operation, but slow and error-prone to do by hand across more than a handful of lines.

It is used by anyone maintaining lists in plain text — ordering a name list, a set of tags or keywords, or a spreadsheet column pasted as text — and by developers and writers cleaning up data such as a list of URLs, log lines, email addresses or CSV values where duplicate entries have crept in from repeated exports or merges. Removing duplicates before importing a list into a spreadsheet, database or mailing tool avoids double-counting or sending something twice.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    To find out how many repeats a list contained, run it once in ascending mode and once in unique mode, then compare the line counts of the two outputs; the difference is the number of exact duplicates removed. The ascending run also places repeats side by side, which makes near-misses such as a trailing space or a different capital easy to spot by eye. Is it case-insensitive matching or keeping the original order that you would want in unique mode?

Popular calculators

All Calculators