How to Remove Duplicates From a List Without Losing the Order

Remove duplicate entries from email lists, SKUs, URLs or names while keeping the original order, and understand case, spaces and first-versus-last choices.

Updated September 29, 2026 5 min read

Use the free Remove Duplicate LinesDelete repeated lines from any list in one click

You merged three sign-up exports into one email list and suspect some people appear twice. A product feed has repeated SKUs. A crawl report lists the same URL many times. Before you send, import or analyse anything, you want one copy of each entry, and ideally in the same order as before.

This guide explains what "duplicate" really means to a computer, the choices that change the result (case, spaces, which copy to keep), and how to deduplicate a list in a browser, in Excel or Google Sheets and on the command line.

When are two lines "the same"?

To a computer, two lines are duplicates only if every character matches. That strictness causes most deduplication surprises:

Line A Line B Identical? Why not
sales@example.com Sales@example.com No Different capital letter
SKU-1042 SKU-1042 No Trailing space
North Region North Region No Double space inside
café café Sometimes not Accents can be stored in two different ways

So before deduplicating, decide what you consider "the same":

  • Case. For email addresses and domain names, case normally does not matter, so Sales@ and sales@ should be merged. For product codes, passwords or case-sensitive IDs, it may matter.
  • Leading and trailing spaces. Almost always accidental, especially in data copied from spreadsheets or PDFs.
  • Blank lines. Usually noise in a list.

Which copy to keep

When a line repeats, the tool keeps one copy. Keeping the first occurrence preserves the order in which items first appeared, which is what you want for most lists. Keeping the last occurrence is useful when later entries are more recent, for example in a log where the latest status for each item appears at the bottom.

Order-preserving versus sorted deduplication

Some methods sort the list as a side effect. That is fine for a keyword list but bad for a ranked list, a playlist or steps in a process. An order-preserving method removes repeats and leaves everything else where it was.

Remove duplicate lines in your browser

Our Remove Duplicate Lines tool deduplicates as you type and keeps the original order.

  1. Open Remove Duplicate Lines.
  2. Paste your list into Your list (one item per line). Click Sample if you want to see how it behaves first.
  3. Set the options:
    • Case sensitive: on by default. Turn it off to treat "Apple" and "apple" as duplicates.
    • Trim whitespace: on by default, so spaces at the start and end of a line are ignored.
    • Remove empty lines: turn on to drop blank lines entirely.
    • When a line repeats, keep the…: choose First occurrence or Last occurrence.
  4. Read the counters: Original lines, Unique lines and Removed.
  5. Copy the result from Unique lines, or download it as a .txt file.

The processing happens in your browser, which matters when the list contains customer emails or other personal data.

A useful habit is to glance at the Removed number before using the result. If you expected a handful of duplicates and it says hundreds, check whether case sensitivity or trimming is set the way you intended.

Other ways to remove duplicates

Excel

Select the range, then choose Data → Remove Duplicates. You can pick which columns must match for a row to count as a duplicate. It keeps the first occurrence and deletes the rest in place, so work on a copy. Excel's comparison ignores case, so "Apple" and "apple" count as duplicates.

In newer versions of Excel, the formula =UNIQUE(A2:A500) returns the unique values in a separate range, leaving the source untouched.

Google Sheets

Use Data → Data cleanup → Remove duplicates, or the formula =UNIQUE(A2:A500). Google Sheets' UNIQUE is case-sensitive, so "Apple" and "apple" both stay.

Spreadsheets are the right tool when your data has several columns and you need to deduplicate whole rows or by one key column.

Command line

On macOS and Linux:

sort -u list.txt

removes duplicates but also sorts the list. To keep the original order and the first occurrence:

awk '!seen[$0]++' list.txt

Add -f to sort to ignore case. The command line is the best choice for very large files or when deduplication is part of a repeatable script.

Tips for common list types

Email lists

Turn off Case sensitive, keep Trim whitespace on and remove empty lines. If the addresses are buried in other text, pull them out first with Extract Emails. Remember that deduplicating by text does not catch the same person using two different addresses.

Keywords

Clean first, then deduplicate. Stray punctuation, capital letters and double spaces create near-duplicates. Remove Extra Spaces handles the spacing, and our guide to cleaning up a messy keyword list covers the rest of the process.

URLs

https://example.com/page and https://example.com/page/ are different strings, as are URLs with and without tracking parameters. Normalise them the same way before deduplicating. Keep case sensitivity on, because URL paths can be case-sensitive on some servers.

Sorted output

If you want the unique items in alphabetical order, deduplicate here and then use Sort Lines, which also has its own option to remove duplicates while sorting.

Finding what was duplicated

Sometimes you need to know which items repeated, not just remove them. Paste the list into the Word Frequency Counter for single-word items, or sort the list so identical lines sit next to each other and are easy to spot.

Frequently asked questions

Does removing duplicates change the order of my list?

Not with an order-preserving method. Our tool keeps every remaining line in its original position; only repeats are removed. Command-line sort -u and some spreadsheet methods do sort the data.

How do I remove duplicates but ignore capital letters?

Turn off the Case sensitive option. Lines that differ only in case are then treated as duplicates, and the first (or last) version you choose to keep is the one that remains.

Why are some duplicates not removed?

The lines differ in a way you cannot see, typically extra spaces inside the line, different capitalisation, or look-alike characters such as a non-breaking space. Clean the text first and check the case option.

Can I keep the most recent entry instead of the first?

Yes. Choose Last occurrence, and the tool keeps the final copy of each repeated line while still returning the lines in their original order.

Is there a limit to how many lines I can paste?

There is no fixed limit; it depends on your device's memory. Lists of tens of thousands of lines are handled comfortably in a modern browser.

Try it now: Remove Duplicate Lines

Loading tool…