Text & writing

How to Remove Duplicate Lines from a List

How to remove duplicate lines from a list of emails, names or keywords while keeping the original order - and why near-duplicates like a stray space or a capital letter slip through most tools.

6 min readUpdated

You have a list - email addresses exported from two sign-up forms, keywords pulled from three reports, names copied out of a spreadsheet - and some lines appear more than once. Removing the repeats sounds trivial, and the obvious approaches quietly do something else as well: they reorder the list, or they leave behind lines that look identical but are not. This guide covers what counts as a duplicate, what to keep, and how to clean a list in a few seconds with Remove Duplicate Lines.

Why the usual methods are not quite right

The classic command-line answer is sort -u, and most spreadsheet tutorials start with sorting the column. Both work, but they change the order. If your list was ranked - search terms by volume, customers by sign-up date, steps in a procedure - the ranking is gone, and putting it back means re-pasting the original and reconciling by hand.

Order-preserving deduplication is a different operation: walk the list from top to bottom, remember every line you have already seen, and drop a line only when it is a repeat of something above it. The first occurrence stays exactly where it was. That is what Remove Duplicate Lines does, and it is the same idea as the well-known awk one-liner that keeps a line only the first time it appears.

Spreadsheets have their own trap. A Remove Duplicates command on a sheet works on whole rows or chosen columns, and whether it treats Apple and apple as the same value depends on the program. For a plain one-item-per-line list, a text tool is simpler: you can see exactly which rule decides what a duplicate is.

What counts as a duplicate

To a computer, two lines are duplicates only if every character matches. Most of the duplicates in a real list fail that test for reasons you cannot see:

  • Trailing spaces. A cell copied out of a spreadsheet or a PDF often carries a space at the end. carol@example.com and carol@example.com followed by a space look the same on screen and compare as different.
  • Indentation. Lines pasted from a document or a code file can start with spaces or tabs.
  • Capital letters. Alice@Example.com and alice@example.com reach the same inbox, because the domain part of an email address is not case-sensitive and almost no mail provider treats the local part as case-sensitive either. Tags, keywords and usernames usually behave the same way.
  • Blank lines. A list pasted from several sources tends to pick up empty lines between the batches, plus one at the very end from the final newline.

Each of the tool's three options handles one of these, so you decide which differences matter instead of getting a fixed rule.

How to remove duplicate lines

  1. Open Remove Duplicate Lines and paste your list, one item per line. The result updates as you type - there is no button to press.
  2. Leave Trim leading and trailing spaces before comparing ticked (it is on by default). Stray spaces stop hiding duplicates, and the kept lines come out trimmed as well.
  3. Tick Ignore case if capitalisation should not make two lines different - right for email addresses, tags and keywords; wrong for passwords, IDs or anything case-sensitive.
  4. Tick Remove empty lines if you want no blank lines at all in the result.
  5. Check the count under the options - it reads, for example, 5 unique lines kept, 4 removed - then copy the result or download it as unique-lines.txt.

A worked example

Here is a short mailing list merged from two exports. It has eight lines: alice@example.com, bob@example.com, Alice@Example.com, carol@example.com indented by two spaces, bob@example.com again, a blank line, dave@example.com, and carol@example.com with a trailing space. Like most pasted text it ends with a newline, so there is an empty ninth line after the last address.

With the default settings - trimming on, case not ignored - the count reads 6 unique lines kept, 3 removed. The second bob goes, the second carol goes because trimming makes the indented and the trailing-space versions identical, and the empty line at the end goes because it repeats the blank line already kept above dave. Alice@Example.com survives, because without Ignore case it is a different string from alice@example.com.

Tick Ignore case and it becomes 5 kept, 4 removed: Alice@Example.com is now recognised as a repeat of the line two above it. The copy kept is always the first one, with its original capitalisation - the tool compares lowercase versions but never lowercases your output. Tick Remove empty lines as well and you get the four clean addresses, alice, bob, carol and dave, in the order they first appeared, with 5 lines removed.

Untick trimming and the same list keeps 7 lines. Both carol variants stay, each with its original spacing, because to an exact comparison an indented line and a line with a trailing space are different text. That is the one case where turning trimming off is right: when leading spaces mean something, such as indented code or a nested outline.

Which copy is kept, and why it matters

Keeping the first occurrence is a choice, not a law. It is the right default for most lists because the first time something appears is usually the meaningful one: the earliest sign-up, the highest-ranked keyword, the step where an instruction was first given. Removing later repeats also means nothing that was ahead of a line ever moves behind it, so the order you see is the order you started with, minus the repeats.

If you want the last occurrence instead - say a log where the newest entry wins - reverse the list first with Text Reverser set to Lines, deduplicate, then reverse the result back.

Near-duplicates the tool will not catch

Deduplication compares whole lines after the options are applied, so some repeats still need a hand. John Smith with two spaces in the middle differs from John Smith, because trimming only touches the ends of a line; collapse internal runs of spaces first with Whitespace Remover. Smith, John and John Smith are the same person to you and two different strings to any tool. And a typo is a new value, not a duplicate.

When you want the list both deduplicated and in alphabetical order, use Sort Lines with Remove duplicates ticked instead - it sorts with real dictionary rules and drops repeats in the same pass.

Is it safe to paste a customer list?

Yes. The deduplication runs as JavaScript in your browser tab; the text is never sent to a server, logged or stored. That matters with email lists and customer names, which are personal data - pasting them into a tool that uploads its input is a data-protection question, not just a convenience one. Close the tab and the list is gone.

Clean your list now

Paste it into Remove Duplicate Lines, keep trimming on, decide whether capital letters matter, and copy back a list with every repeat gone and every original line in its original place - free, instant, and private.

Frequently asked questions

How do I remove duplicate lines without changing the order?
Use an order-preserving tool instead of sorting. Remove Duplicate Lines reads your list from top to bottom and drops a line only when it repeats one already seen, so the first occurrence of every line stays exactly where it was. Methods built on sorting, like sort -u on the command line, remove duplicates too but also reorder the whole list.
Why are some duplicate lines not being removed?
Because they are not identical character for character. The usual culprits are a trailing space, leading indentation, different capitalisation or two spaces in the middle of a line. Keep Trim leading and trailing spaces ticked, tick Ignore case if capitals do not matter, and collapse internal double spaces with a whitespace tool before deduplicating.
Which duplicate is kept when I remove duplicate lines?
The first one. Every later copy is removed, and the kept line keeps its original spelling and capitalisation even when Ignore case is on - the tool compares lowercase versions behind the scenes but never changes your text. To keep the last occurrence instead, reverse the list, deduplicate it and reverse it back.