How to Remove Duplicate Lines in Any Text

Duplicate lines are everywhere — pasted email lists, exported CSV rows, log files, keyword lists. Here's how to clean them fast, plus a free instant tool.

The fastest way to remove duplicate lines is to use a free online duplicate line remover that runs in your browser. Paste your list, and unique lines appear instantly — nothing is uploaded.

1. Using a free online tool (instant)

Copy your list, paste it into the Duplicate Line Remover, and the duplicates vanish in a second. Optional controls let you ignore case, trim whitespace, remove empty lines, sort, or keep the first or last occurrence of each duplicate.

2. In Excel or Google Sheets

In Excel: select the column → DataRemove Duplicates. In Google Sheets: DataData cleanupRemove duplicates.

3. In the terminal (macOS / Linux)

To remove all duplicate lines while preserving original order: awk '!seen[$0]++' file.txt > clean.txt

To sort alphabetically and deduplicate: sort -u file.txt

What counts as a duplicate?

By default, two lines are duplicates only if they match exactly, including case and spacing. Turn on ignore case so Apple and apple collapse to one, and trim whitespace so "apple" and " apple " are treated as the same.

4. In a code editor (VS Code / Notepad++)

In VS Code, select the lines, open the command palette (⌘⇧P), and run Sort Lines Ascending, then remove adjacent duplicates. Better, install the Sort Lines extension and pick Sort lines (remove duplicates) for a one-step cleanup. Notepad++ users can use the TextFX plugin (TextFX Tools → Sort Lines Case Insensitive → remove duplicate lines).

5. With a quick Python one-liner

If you're comfortable with a terminal, Python removes duplicates while preserving order: python3 -c "import sys; seen=set(); [print(x) for x in sys.stdin if x.rstrip() not in seen and not seen.add(x.rstrip())]" < file.txt

6. In Google Sheets

Paste your column into Sheets, then Data → Data cleanup → Remove duplicates. To get a count first, use a formula like COUNTA(UNIQUE(A:A)) so you know how many unique values you have before cleaning.

Real-world examples

Before and after

Without cleaning, a messy list might read: apple, banana, apple, cherry, banana, apple. After removing duplicates it's a tidy apple, banana, cherry. Use ignore case if you want Apple and apple treated as one, and sort if you want the output in alphabetical order.

Frequently asked questions

Does removing duplicate lines change the order?

Not if you keep the keep first occurrence option on. The first time a line appears is kept, so the remaining order stays the same as your original input.

Can I deduplicate a huge file?

Yes. A browser tool handles thousands of lines, but for multi-million-line logs, use the command line (awk or sort -u) which streams the file instead of holding it all in memory.

Is my data private?

With ToolCubby's tool nothing is uploaded. Your text is processed locally in your browser and never leaves your device.

Why duplicate lines appear

Most duplicates come from merging data — combining two exported lists, appending a new batch to an old one, or repeatedly copying the same block of text. Crawlers and forms also repeat identical lines with surprising ease. The moment you join sources, duplicates are almost guaranteed.

Practical tips

Related tools