utilobox

How to remove duplicate lines from a list and keep the right ones

You merged a few lists and now the same address, keyword or name appears several times. This guide shows how to remove duplicate lines from pasted text, which of the four duplicate settings to pick, and why two lines that look the same sometimes survive.

Last updated:

Remove duplicate lines: what counts as a duplicate

A duplicate here is a line whose full text is the same as another line’s. Nothing is compared part by part. “anna” and “anna ” with one extra space at the end are different lines, and so are “Anna” and “anna” unless you ask the tool to ignore capital letters. The tool does not know that two lines mean the same thing; it only knows when they are written the same way.

That sounds strict, but it is exactly what makes the result predictable. If a line survives, there is a visible difference between it and its twin, and you can find it. The cleanup options in this guide exist to remove the invisible differences, such as spaces and case, so that lines which are the same in your head become the same in the tool.

Step by step with Remove duplicate lines

To remove duplicate lines, paste the list into ‘Input (one item per line)’. The result appears at once in ‘Result’, and four counters show ‘Lines before’, ‘Lines after’, ‘Duplicates removed’ and ‘Empty lines removed’. Duplicates are already removed when you paste, because the setting ‘Keep the first of each’ is chosen from the start, so check that before you assume nothing happened.

Open the ‘Repeated lines’ menu to pick another rule, tick ‘Trim spaces around each line’ or ‘Remove empty lines’ if needed, and read the counters again. Then press ‘Copy’, or ‘Download .txt’ to save the list as a file called lines.txt. ‘Use result as input’ moves the result into the input box so you can run another pass, and ‘Clear’ empties the input.

The settings and the text are kept in this browser, so a refresh does not lose your work. Nothing is uploaded.

The four duplicate settings, with a small example

Take the list apple, pear, apple, plum, pear, fig. It has six lines, of which apple and pear appear twice. The settings give different answers to different questions.

‘Keep the first of each’ answers “give me the list without repeats”. The result is apple, pear, plum, fig, in the order of first appearance, and the counter reports 2 duplicates removed. ‘Keep only lines that appear once’ answers “which items were never repeated?”. It drops every copy of apple and pear and leaves plum and fig. ‘Keep only repeated lines’ answers “what was duplicated?”. It lists apple and pear once each. ‘Leave as they are’ turns removal off, which is useful when you want only the trimming, numbering or sorting.

  • Keep the first of each: a clean list with one copy of everything.
  • Keep only lines that appear once: items without a twin, for example customers who bought only once.
  • Keep only repeated lines: the items that occur more than once, each shown a single time.
  • Leave as they are: no duplicate handling, only the other options.

Make near-duplicates match: case and spaces

Most duplicates that survive an attempt to remove duplicate lines differ by invisible characters. The two options that fix most of them are ‘Ignore upper/lower case’ and ‘Trim spaces around each line’. Imagine eight lines: anna, Bob, anna, an empty line, bob with a space at the end, carl, Anna and carl. With the default exact match you get six lines, because only the two exact repeats are removed.

Now tick the case option, the trim option and ‘Remove empty lines’. The empty line goes first, the trailing space is trimmed, and the case differences are ignored, so the eight lines become three: anna, Bob and carl. Four lines are reported as duplicates and one as an empty line. When case is ignored, the copy that is kept is the first one, with its original capital letters, so the surviving entry is the spelling that appeared first.

Trimming only touches the two ends of a line. A double space inside a name, as in “Mary Ann”, stays and keeps the line different from “Mary Ann”. If you suspect that, use the Case converter’s ‘Remove extra spaces’ button first, then come back.

The order in which the options run

The tool always works in one order: trim, remove empty lines, handle duplicates, sort, then add the prefix, suffix and numbers. This matters when you combine options. Because trimming comes first, a line with trailing spaces is trimmed before the duplicate check, so it can match its twin. Because duplicate handling comes before sorting, you never sort lines that are about to be removed.

It also means that line numbers and prefixes are added at the very end, after the list is final. Numbers start at 1 and use the form “1. text”. A prefix and suffix can wrap each item for pasting into somewhere else, such as quotes and a comma around every line. Do not run the tool twice with a prefix on, or the second pass will treat the decorated lines as the text.

What this tool cannot do

It can remove duplicate lines only when whole lines match. It cannot find duplicates by one column of a table, so a list of rows such as “anna, 2024” and “anna, 2025” is treated as two different lines even if you care only about the name. If you need that, first reduce the list to the column you care about, then remove the duplicates.

It does not recognize near matches such as a misspelling, a nickname, an address written two ways, or a line with different punctuation. Accents count as differences, so “café” and “cafe” are different lines. It does not treat a line break inside a quoted text as part of the same item, because lines are simply the pieces between line breaks.

Empty lines are kept unless you tick ‘Remove empty lines’; when duplicates are handled, a repeated empty line is itself a repeat and only one is kept. A very long list works, but the saved copy in your browser is skipped for texts above 300,000 characters.

Check the result before you rely on it

Use the counters as a quick audit. Lines before minus lines after always equals duplicates removed plus empty lines removed. Note that ‘Duplicates removed’ counts every line that was dropped by the duplicate rule, so under the two “only” settings it can be far larger than the number of repeated items.

Spot-check a couple of the entries you know were repeated, and scan the list for pairs that look alike. If two almost-identical lines remain, copy one into the Text compare (diff) tool next to the other, in Characters mode, and the hidden difference is shown. Finally, keep your original list until you have used the result.

Questions and answers

How do I remove duplicate lines from a list?

Paste the list with one item per line. With ‘Keep the first of each’ selected, which is the starting setting, repeated lines are removed and each first copy stays where it was.

Why were two similar lines not removed?

The tool compares whole lines exactly. Look for a different capital letter, a space at the end, or an accent, then tick ‘Ignore upper/lower case’ or ‘Trim spaces around each line’.

How do I see which lines were duplicated?

Choose ‘Keep only repeated lines’. Each line that occurs more than once is shown a single time.

Does it keep the original order?

Yes, unless you pick a sort order. The first copy of each line stays in its original position.

Can it compare only one column of a table?

No. It works on whole lines. Reduce the list to the column you need first, then remove the duplicates.

Is my list sent to a server?

No. The lines are processed in your browser, and a copy is kept in this browser only so a refresh does not lose it.