Remove duplicate lines from any text with case-sensitive or case-insensitive matching. Optionally remove blank lines and sort the output โ copy the result instantly.
1 lines
Options
Paste lines and click Remove Duplicates
Data deduplication is an essential step in data preparation, log analysis, contact list consolidation, and database ingestion. Duplicate rows consume unnecessary storage, skew analytical aggregations, and cause primary key collision errors during database imports.
When stripping duplicates from a list of strings, developers choose between two algorithmic approaches:
| Strategy | Time Complexity | Space Complexity | Preserves Original Order |
|---|---|---|---|
| Hash Set (Order Preserving) | $O(N)$ | $O(N)$ | Yes - retains the very first occurrence of each unique line |
Sort & Unique (sort | uniq) | $O(N \log N)$ | $O(1)$ auxiliary | No - reorders items alphabetically before removing adjacent duplicates |
| Frequency Map | $O(N)$ | $O(N)$ | Yes - tracks exact count of duplicate occurrences per line |
"admin@example.com" and "Admin@Example.com" are treated as duplicates.JavaScript
function removeDuplicates(text, caseSensitive = true, trimWhitespace = true) {
const lines = text.split(/\r?\n/);
const seen = new Set();
const uniqueLines = [];
for (const line of lines) {
const key = trimWhitespace ? line.trim() : line;
const lookupKey = caseSensitive ? key : key.toLowerCase();
if (!seen.has(lookupKey)) {
seen.add(lookupKey);
uniqueLines.push(key);
}
}
return uniqueLines.join('\n');
}
Python
def deduplicate_lines(text: str, case_sensitive: bool = True) -> str:
seen = set()
unique = []
for line in text.splitlines():
check_key = line if case_sensitive else line.lower()
if check_key not in seen:
seen.add(check_key)
unique.append(line)
return "\n".join(unique)
sort -u) rather than in-memory hash sets.\n) or Windows (\r\n) line termination sequences across deduplication passes to avoid dirtying Git diffs.This website and utility are provided for general informational, calculation, and educational purposes only. Always verify critical computation outputs prior to professional deployment or financial use. See our Terms of Service and Privacy Policy for full governance details.