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:
| Mode | What it does | Use case |
|---|---|---|
| Remove duplicates (keep first) | Keep first occurrence of each line, drop subsequent | Most common — preserves order |
| Remove duplicates (keep last) | Keep last occurrence of each line | When later entries override earlier (e.g., updated records) |
| Keep only duplicates | Show only lines that appear more than once | Auditing data quality, finding repeat entries |
| Keep only unique (never repeated) | Show only lines that appear exactly once | Finding singletons, isolating one-off entries |
Method 1: Online Tool (Browser-Based)
Using our free Remove Duplicate Lines tool:
- Open the tool in any browser.
- Paste your text into the input field.
- 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
- Click Process.
- 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
- Paste your list into column A (one item per row)
- Select the column or data range
- Data tab → Remove Duplicates
- Check the columns to consider in the dialog
- Click OK — Excel removes duplicates, keeping the first occurrence
- 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:
- Open your text file in Notepad++
- Edit menu → Line Operations → Sort Lines Lexicographically Ascending (sorts first — required for next step)
- Edit menu → Line Operations → Remove Consecutive Duplicate Lines
- 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 size | Recommended method | Typical time |
|---|---|---|
| Under 1,000 lines | Any tool works | Instant |
| 1,000 - 100,000 lines | Online tool or Excel | 1-5 seconds |
| 100,000 - 1 million lines | Online tool (browser-based) | 5-30 seconds |
| 1 million - 10 million lines | Command-line (sort/uniq, awk) | 10-60 seconds |
| Over 10 million lines | Python with pandas, or database | Minutes |
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:
- Open browser DevTools → Network tab
- Run deduplication on test text
- If no POST request with your text content appears, the tool is client-side
- 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.
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
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.
