Utility · Apr 15, 2026 · Updated Oct 13, 2026 · 4 min read

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:

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 linesBefore the fixNow
apple, constructor, toString, valueOf, hasOwnProperty, __proto__ (each once)only "apple" kept: the other five silently deletedall six kept
café (composed) and café (decomposed)kept twicekept once
apple and apple + non-breaking space (trim on)kept oncekept once
apple and apple + zero-width space (trim on)kept twicekept once
Straße and STRASSE (ignore case on)kept twicekept twice
one (CR LF), one (LF), twoone, twoone, 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

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.

Open Remove Duplicate Lines →

Frequently Asked Questions

Does the tool keep the first or last occurrence?
The first occurrence is kept. If you need to keep the last occurrence, reverse your input, deduplicate, then reverse again using our Sort Lines tool.
How large a file can I process?
Large lists are fine: in our test the tool's deduplication code handled 100,000 email addresses in 0.17 s and 1,000,000 in 1.4 s (Node 22, the same V8 engine as Chrome). Pasting and displaying a million-line text box is the slower part, so for very large files the command line (awk '!seen[$0]++') is more comfortable.
Why are my 'duplicates' not being detected?
Usually invisible differences: trailing spaces or tabs (turn on Trim whitespace, which also strips non-breaking and zero-width spaces at the ends), different letter case (turn on Ignore case), or a near-duplicate such as a trailing comma. Accents stored in different Unicode forms are now treated as the same line.
Can I dedupe a CSV by row?
Yes, for full-row duplicates. Paste your CSV data and the tool treats each line as one entry. For column-specific dedup (e.g., 'unique by email column'), you'd need a spreadsheet tool instead.

Published Apr 15, 2026 · Updated Oct 13, 2026 by Derek Giordano

📚 References & Further Reading
Browse all utility tools →
⚡Remove Duplicate Lines→
GuideThe Complete Guide to Sorting Text Lines→UtilityHow AI Text Detection Works→CSSCSS Text Effects: Gradients, Shadows & Transforms→GuideHow Fancy Text Works (And When Not to Use It)→ContentHow to Analyze Text Readability and Word Count→ImageHow to Convert SVG to PNG at Any Resolution (2026)→ContentHow to Convert Text Case: Uppercase, Lowercase, Title Case→ContentHow to Count Words and Characters in Text→