Free website & SEO check: see your score in under a minute  ·  Check my website →Premium Windows software for marketers: talk to us for access and pricing  ·  Explore the software →
Tutorial Updated May 22, 2026  ·  8 min read

How to Remove Duplicate Lines from Text in 2026: Every Method

The deduplication itself is trivial; the part that bites people is picking the wrong mode and silently deleting the copy they actually needed. Most students who bring me a "the tool ate my data" problem didn't hit a bug, they ran "keep first" when the corrected entry was the last one, or left case-sensitivity on a toggle they didn't understand. So this guide covers every method (browser, Excel, Notepad++, command-line) and, more importantly, how to choose the mode that keeps the right line.

Quick verdict: Open our free Remove Duplicate Lines tool, paste text, pick a mode (keep first is the safe default), set case-sensitivity deliberately, and process. Browser-based, no upload, unlimited size, clean in seconds. The one rule that prevents regret: decide which copy you need to survive before you run it, and keep a backup.

The Four Deduplication Modes

Most use cases fit one of these four modes:

ModeWhat it doesUse case
Remove duplicates (keep first)Keep first occurrence of each line, drop subsequentMost common — preserves order
Remove duplicates (keep last)Keep last occurrence of each lineWhen later entries override earlier (e.g., updated records)
Keep only duplicatesShow only lines that appear more than onceAuditing data quality, finding repeat entries
Keep only unique (never repeated)Show only lines that appear exactly onceFinding singletons, isolating one-off entries
Our tool supports all four modes. Most other dedup tools only offer "remove duplicates."

Method 1: Online Tool (Browser-Based)

Using our free Remove Duplicate Lines tool:

  1. Open the tool in any browser.
  2. Paste your text into the input field.
  3. Choose options:
    • Mode: Remove duplicates / Keep duplicates / Keep unique
    • Case-sensitive: on/off
    • Trim whitespace: on/off (treats " hello " same as "hello")
    • Sort: alphabetical, by frequency, or preserve order
    • Ignore empty lines: on/off
  4. Click Process.
  5. Copy the result or download as text file.

Performance: Handles up to ~1 million lines in browser without issue. Processing is instant for under 100k lines.

Privacy: All processing happens locally in your browser. Text never uploads to any server.

Method 2: Excel / Google Sheets

Excel: Remove Duplicates feature

  1. Paste your list into column A (one item per row)
  2. Select the column or data range
  3. Data tab → Remove Duplicates
  4. Check the columns to consider in the dialog
  5. Click OK — Excel removes duplicates, keeping the first occurrence
  6. Excel shows: "X duplicate values found and removed; X unique values remain"

Google Sheets: UNIQUE function

=UNIQUE(A1:A1000)

Returns deduplicated values in a new column. Live-updates if source data changes.

Google Sheets: COUNTIF for duplicate detection

// In column B, mark duplicates
=IF(COUNTIF(A:A, A1)>1, "DUPLICATE", "UNIQUE")

// Filter or sort by column B to isolate duplicates

Limitations: Excel and Google Sheets work well for lists under 100,000 rows. Beyond that, performance degrades. Excel's Remove Duplicates is case-insensitive only; for case-sensitive dedup, use formulas or an online tool.

Method 3: Notepad++ (Windows)

Free text editor with built-in line tools:

  1. Open your text file in Notepad++
  2. Edit menu → Line Operations → Sort Lines Lexicographically Ascending (sorts first — required for next step)
  3. Edit menu → Line Operations → Remove Consecutive Duplicate Lines
  4. Alternatively: TextFX plugin → TextFX Tools → Sort lines case sensitive (or insensitive) and remove duplicates

Limitations: Notepad++ requires sorting first because it only removes consecutive duplicates. To preserve original order, use a different tool.

Method 4: Sublime Text / VS Code

Sublime Text

Edit menu → Permute Lines → Unique. Removes duplicates instantly without requiring pre-sort. Preserves original line order.

VS Code with extensions

Install "Sort lines" or "Unique Lines" extension. Then Command Palette (Ctrl+Shift+P) → "Remove Duplicate Lines" or similar command. Several extensions offer different modes.

Method 5: Command Line

Unix / Mac / Linux / WSL

# Remove duplicates (output sorted)
sort file.txt | uniq > output.txt

# Remove duplicates (preserve original order)
awk '!seen[$0]++' file.txt > output.txt

# Show only duplicates (lines appearing more than once)
sort file.txt | uniq -d > duplicates.txt

# Show only unique lines (appearing exactly once)
sort file.txt | uniq -u > uniques.txt

# Count occurrences of each line
sort file.txt | uniq -c > counts.txt

# Case-insensitive deduplication
sort -f file.txt | uniq -i > output.txt

PowerShell (Windows)

# Remove duplicates preserving order
Get-Content file.txt | Select-Object -Unique | Set-Content output.txt

# Remove duplicates with sorted output
Get-Content file.txt | Sort-Object -Unique | Set-Content output.txt

# Count occurrences of each line
Get-Content file.txt | Group-Object | Sort-Object Count -Descending

Command-line approaches handle massive files (gigabytes) that browser-based tools can't. Best for ad-hoc cleaning of large data exports.

Method 6: Programmatic (Code)

Python

# Remove duplicates, preserve order
with open('input.txt') as f:
    lines = f.readlines()

seen = set()
unique = [x for x in lines if not (x in seen or seen.add(x))]

with open('output.txt', 'w') as f:
    f.writelines(unique)

# One-liner with pandas
import pandas as pd
pd.read_csv('input.txt', header=None).drop_duplicates().to_csv('output.txt', index=False, header=False)

JavaScript / Node.js

const fs = require('fs');
const text = fs.readFileSync('input.txt', 'utf-8');
const unique = [...new Set(text.split('\n'))].join('\n');
fs.writeFileSync('output.txt', unique);

Use programmatic deduplication for ETL pipelines, recurring jobs, and very large files where browser tools time out.

Advanced Deduplication Scenarios

Case-insensitive deduplication

Treat "hello," "Hello," and "HELLO" as the same. Useful for email lists where capitalization varies but the underlying address is the same. Most modern tools include this toggle; our tool defaults to case-insensitive.

Trim-whitespace deduplication

Treat " hello", "hello ", and "hello" as the same. Useful for lists where copy-paste introduced varying leading/trailing whitespace. Toggle in our tool.

Partial-column deduplication

In Excel: when removing duplicates from multi-column data, you can specify which columns to consider. E.g., dedupe by email column even if other columns differ.

Fuzzy / near-duplicate detection

Strings like "john@example.com" vs "John@Example.com" vs "john@example.com " are functionally the same. Tools like Python's fuzzywuzzy library or dedicated dedup software handle these. Our tool with case-insensitive + trim-whitespace catches most common variants.

Frequency analysis

Beyond just "is this a duplicate," sometimes you want to know how many times each line appears. Useful for analyzing the most common items in a list (top search terms, most-clicked URLs). Use the Frequency mode in our tool.

Common Real-World Use Cases

Cleaning an email subscriber list

Export subscribers, dedupe case-insensitively, re-import. Typical reduction: 5-15% of records were duplicates from multiple signup forms. See our email dedup guide.

Removing duplicate URLs from a crawl export

SEO crawlers often export with query parameter variants. Dedupe by stripping parameters first, then dedup the cleaned list.

Cleaning a survey free-text response column

Use Frequency mode to find the most common open-text responses. Surfaces themes for qualitative analysis.

Deduplicating user-generated tags

"Marketing," "marketing," "MARKETING" all reference the same concept. Case-insensitive dedup normalizes them.

Cleaning log files for unique events

Server logs often contain duplicate entries from retries. Dedupe by full log line, or by extracted timestamp+endpoint.

Removing duplicates from contact lists across CRM exports

When merging contact lists from multiple sources, dedup catches the overlapping accounts.

Cleaning copy-pasted product SKUs from spreadsheets

SKU lists from suppliers often have duplicates from version variants or list errors. Dedupe before importing.

When Not to Deduplicate

  • When duplicates carry meaning. A list of survey responses where the same answer appearing 50 times signals popularity — don't dedupe; count instead.
  • When order or relationship matters. If "John, San Francisco" and "John, New York" are different people, you can't dedupe just by name.
  • For audit logs of events. Each event represents something that happened — deduplicating may hide important pattern data.
  • For voting or vote-counting. Each vote is an instance; dedup would erase the count.
  • For transactional records. Multiple identical-looking transactions might be intentional (recurring payment, multiple purchases).

Default to "remove duplicates" only when duplicates are noise. When they're signal, count instead.

Performance: Tool by Input Size

Input sizeRecommended methodTypical time
Under 1,000 linesAny tool worksInstant
1,000 - 100,000 linesOnline tool or Excel1-5 seconds
100,000 - 1 million linesOnline tool (browser-based)5-30 seconds
1 million - 10 million linesCommand-line (sort/uniq, awk)10-60 seconds
Over 10 million linesPython with pandas, or databaseMinutes
For most everyday use cases (under 100k lines), online tools are fastest because there's no install. Reserve command-line for huge files.

Privacy: Browser vs Server Dedup Tools

Some online dedup tools process server-side (upload your text to their server). For sensitive lists — customer emails, internal employee data, prospect lists — this creates risk.

Verify if a tool is client-side:

  1. Open browser DevTools → Network tab
  2. Run deduplication on test text
  3. If no POST request with your text content appears, the tool is client-side
  4. If a POST request uploads your text, server-side

Our tool processes everything in your browser. Verify with the above test if it matters for your data.

From the classroom

The lesson I make every student learn the slightly hard way: run the dedup in "keep only duplicates" mode first, before you remove anything. It sounds backwards, but that mode shows you exactly which lines are about to be collapsed, so you see the damage before you do it instead of after. A student once deduped a contact list "keep first" and lost the updated phone numbers that were sitting in the later, corrected rows. Had she previewed the duplicates first, she'd have noticed the later copies were the good ones and switched to "keep last." Treat "show me the duplicates" as a preview step, not a separate feature. Look before you delete, and the mode choice becomes obvious.

Frequently Asked Questions

Yes — Excel's Remove Duplicates keeps the first occurrence of each value and preserves the original row order of the remaining rows. Other rows shift up to fill removed positions.

Most basic dedup tools work on full-line matching. For partial match (e.g., "first column only"), split your data into columns first (Excel, Google Sheets) and dedupe by specific columns, or use regex preprocessing in command-line tools.

Modern browsers comfortably handle 100MB+ text files (millions of lines). Performance depends on your device's RAM. For predictable speed up to 10 million lines, command-line is usually faster.

Depends on the mode. "Keep first" preserves the first occurrence's exact formatting. "Keep last" preserves the last. If duplicates differ only in case or whitespace and your dedup is case-insensitive/trim-whitespace, the kept version is the first or last regardless of which casing/whitespace it has.

Concatenate the files first (cat file1.txt file2.txt > combined.txt), then dedupe the combined file. Or paste contents of both into our online tool. Excel's Remove Duplicates works on a single sheet but you can combine sheets first.

Always keep a backup of the original before deduping. In Excel, Ctrl+Z works immediately. For command-line, redirect to a new file rather than overwriting the original. For our online tool, the input area still contains your original text after processing — copy from there if needed.

Pick the mode, then dedupe

Removing duplicate lines is a 5-second task with the right tool. Browser-based for under 100k lines (privacy + speed), Excel for spreadsheet-native data, command-line for files over a million lines. The part that actually matters isn't speed, it's the mode: "keep first" for most lists, "keep last" when later copies are corrections, and "keep only duplicates" as a preview before you delete. Decide which copy must survive, keep a backup, then run it.