<!-- How to Remove Duplicates from a List | DataSwitch Pro -->
<!-- Canonical: https://dataswitchpro.com/guides/remove-duplicates-from-a-list/ -->
> Remove duplicate lines from any list with Excel, Google Sheets, Notepad++, the command line, Python or a free tool — and find which values repeat.

[Home](https://dataswitchpro.com/) › [Guides](https://dataswitchpro.com/guides/)

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

By the DataSwitch Pro team · November 21, 2026 · 4 min read

## Quick answer

Paste the list into a [duplicate line remover](https://dataswitchpro.com/remove-duplicate-lines/), 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](https://dataswitchpro.com/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?

- **Trailing or leading spaces** — very common in data copied from web pages and PDFs. Trim before comparing.
- **Letter case** — `Anna@Example.com` vs `anna@example.com`. Email addresses are case-insensitive in practice, so compare in lower case.
- **Look-alike characters** — a non-breaking space, a tab instead of a space, or curly vs straight quotes.
- **Different line endings** — files that mix Windows (CRLF) and Unix (LF) endings can leave an invisible carriage return on some lines. Most tools, including the one above, normalise this.

## 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](https://dataswitchpro.com/comma-separator/)), or a table for a database (see [how to import a CSV into SQL](https://dataswitchpro.com/guides/import-csv-into-sql-database/)).

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

[Remove Duplicate Lines](https://dataswitchpro.com/remove-duplicate-lines/)[Comma Separator](https://dataswitchpro.com/comma-separator/)[Excel to CSV](https://dataswitchpro.com/excel-to-csv/)

## 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

- [Why Your CSV Opens in One Column in Excel (and How to Fix It)](https://dataswitchpro.com/guides/csv-opens-in-one-column-excel/)
- [How to Keep Leading Zeros (and Long Numbers) When Opening CSV in Excel](https://dataswitchpro.com/guides/keep-leading-zeros-csv-excel/)
- [Fix Garbled Characters (Ã©, â€™, Ã¨) in CSV Files Opened in Excel](https://dataswitchpro.com/guides/fix-garbled-characters-csv-excel/)
- [How to Open an XML File in Excel as a Table](https://dataswitchpro.com/guides/open-xml-file-in-excel/)
