DataSwitch Pro Private, in-browser data converter

How to Remove Duplicates from a List (Excel, Sheets, Notepad++, Code)

By the DataSwitch Pro team · · 4 min read

Quick answer

Paste the list into a duplicate line remover, which keeps the first copy of each line in the original order. In Excel 365 or Google Sheets use =UNIQUE(A2:A1000) (wrap it in SORT() to sort); in older Excel use Data › Remove Duplicates. On the command line, sort -u list.txt sorts and de-duplicates, and awk '!seen[$0]++' list.txt de-duplicates without changing the order.

Duplicates creep into every list that is built by merging or copying: email exports from two tools, SKUs pasted from several sheets, keywords from different research sessions, log lines. Removing them is easy — the details that trip people up are invisible differences (spaces and letter case), whether the original order must survive, and whether you need to remove the repeats or find them.

Method 1: an online duplicate remover (fastest)

  1. Open Remove Duplicate Lines and paste your list, one item per line, or upload a .txt or .csv file.
  2. Leave Trim spaces on and Case-sensitive off so that apple, Apple and apple count as one.
  3. Pick a sort order if you want one — Natural puts item 2 before item 10.
  4. Copy the result or download it as a text file.

The tool runs in your browser, so the list is never uploaded. To see the duplicates instead of removing them, set Keep to Only lines that repeat and turn on the counts.

Method 2: Excel and Google Sheets

Excel 365, Excel 2021 and Google Sheets have a UNIQUE function that returns each value once, leaving the original column untouched:

=UNIQUE(A2:A1000)
=SORT(UNIQUE(A2:A1000))

Any Excel version: select the column, then Data › Remove Duplicates. This edits the sheet in place, so work on a copy. When a table has several columns, the dialog lets you choose which columns must match for two rows to count as duplicates.

To highlight duplicates without deleting them: Home › Conditional Formatting › Highlight Cells Rules › Duplicate Values, or count them with =COUNTIF($A$2:$A$1000, A2) in a helper column and filter for values greater than 1.

Excel's comparison ignores letter case but not spaces, so "apple " with a trailing space is a different value. Clean the column first with =TRIM(A2) if your data came from another system.

Method 3: Notepad++ and VS Code

In Notepad++, use Edit › Line Operations › Remove Duplicate Lines (removes every repeat) or Remove Consecutive Duplicate Lines (only repeats that sit next to each other — sort first). Edit › Line Operations › Sort Lines Lexicographically Ascending sorts the file.

In VS Code, select the lines and run Delete Duplicate Lines from the Command Palette (available in recent versions), or Sort Lines Ascending to sort them.

Method 4: command line

sort -u list.txt > unique.txt              # sort and remove duplicates
awk '!seen[$0]++' list.txt > unique.txt    # remove duplicates, keep original order
sort list.txt | uniq -d                    # print only the lines that repeat
sort list.txt | uniq -c | sort -rn         # count each line, most frequent first

uniq only compares neighbouring lines, which is why it is always used after sort. Add -f to sort and -i to uniq to ignore case. On Windows, PowerShell does the same with Get-Content list.txt | Sort-Object -Unique.

Method 5: Python

lines = open("list.txt", encoding="utf-8").read().splitlines()
seen, unique = set(), []
for line in lines:
    key = line.strip().lower()          # ignore spaces and case
    if key and key not in seen:
        seen.add(key)
        unique.append(line.strip())
print("\n".join(unique))

For a table rather than a plain list, pandas does it in one call: df.drop_duplicates(subset=["email"], keep="first").

Why are some duplicates not removed?

After de-duplicating

Once the list is clean, you often need it in another shape: one line with commas for a SQL WHERE … IN filter (use the Comma Separator), or a table for a database (see how to import a CSV into SQL).

Try it on your own file. Free, private, and processed in your browser.

Frequently asked questions

How do I remove duplicates in Excel but keep the first one?

Data › Remove Duplicates keeps the first occurrence of each value and deletes the later ones. =UNIQUE() also returns values in order of first appearance.

How do I remove duplicates without sorting?

Use a tool or method that keeps order: the Remove Duplicate Lines tool with sorting off, =UNIQUE() in Excel 365, or awk '!seen[$0]++' on the command line.

How do I find duplicates without removing them?

Use conditional formatting in Excel, sort | uniq -d on the command line, or the tool's Only lines that repeat option with counts.

Is removing duplicates case-sensitive?

It depends on the tool. Excel ignores case; sort -u and Python's set do not unless you lower-case the text first. The online tool ignores case by default and has a switch to change it.

More guides