How to Remove Duplicate Lines from Any Text
How to remove duplicate lines when the edge cases matter: invisible whitespace, accents stored two ways, case, line endings. Testing them turned up a real bug: lines like "constructor" and "toString" were silently deleted. It is fixed, and so are four other tools with the same flaw.
What Counts as "the Same Line"
Two lines are duplicates only if the tool compares them the way you think it does. Strings that look identical can differ in invisible ways, and lines that differ can mean the same thing. The decisions to make:
- Whitespace: a trailing space, a non-breaking space (U+00A0) or a zero-width space (U+200B) at the end makes a different string.
- Case: "Apple" and "apple".
- Unicode form: "café" can be stored as one character é (composed) or as e plus a combining accent (decomposed); they display identically.
- Line endings: files from Windows end lines with CR LF, others with LF.
- Near-duplicates such as "John Smith" and "John Smith," are different strings to every exact-match tool.
Edge Cases We Tested, and a Bug We Found
We ran each case through the Remove Duplicate Lines tool's own code (October 14, 2026; script in our test folder). The first row was a real bug, fixed the same day:
| Input lines | Before the fix | Now |
|---|---|---|
| apple, constructor, toString, valueOf, hasOwnProperty, __proto__ (each once) | only "apple" kept: the other five silently deleted | all six kept |
| café (composed) and café (decomposed) | kept twice | kept once |
| apple and apple + non-breaking space (trim on) | kept once | kept once |
| apple and apple + zero-width space (trim on) | kept twice | kept once |
| Straße and STRASSE (ignore case on) | kept twice | kept twice |
| one (CR LF), one (LF), two | one, two | one, two |
The bug is a classic JavaScript one: the tool remembered seen lines in a plain object, and every plain object already "contains" names like constructor and toString through its prototype, so those lines looked like repeats. Any text with a line or word that matches one of those names is affected. We found the same pattern in four more of our tools (word counts in Keyword Density and Text Analyzer, template variables in the AI Prompt Template Builder, and two internal lookups), fixed all of them, and added a build check so it cannot come back. If you deduplicate in your own code, use a Set or Map.
Ignoring case uses simple lowercasing, so German ß and SS stay different; if that matters, normalize them yourself first.
Choosing Settings
- Trim whitespace (on by default): safe for almost every list.
- Ignore case: right for domain names, hashtags and keyword lists. For email addresses the domain is case-insensitive, but the part before @ may legally be case-sensitive (RFC 5321); in practice large providers such as Gmail treat it as case-insensitive, so ignoring case is usually right for marketing lists.
- Remove empty lines: otherwise one blank line is kept like any other line.
- Sort: off keeps the first occurrence of each line in its original order; on sorts the result alphabetically.
On the Command Line
awk '!seen[$0]++' file.txt keeps the first of each line in order; sort -u file.txt sorts and deduplicates. Both compare raw bytes, so they keep the composed/decomposed café pair and lines that differ by trailing spaces; strip carriage returns first with tr -d '\r' when mixing Windows and Unix files.
Try the tool
Clean up lists, CSVs, and log files in seconds.
Frequently Asked Questions
Does the tool keep the first or last occurrence?
How large a file can I process?
Why are my 'duplicates' not being detected?
Can I dedupe a CSV by row?
Published Apr 15, 2026 · Updated Oct 13, 2026 by Derek Giordano
Browse all utility tools →