Duplicate Line Remover
Remove duplicate lines while keeping the first or last occurrence.
- Runs locally in your browser
- No upload required
Try it
Supported formats
Privacy
Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.
Kept 3 distinct line(s) and removed 1 duplicate(s).
How it works
- Normalised CRLF and lone CR line endings to LF.
- Compared each line as-is.
- Compared lines case-sensitively.
- Kept the first occurrence of each distinct line.
- Rejoined the surviving lines in their original order.
- The result is idempotent: a second run finds no duplicates.
Methodology
- Normalise CRLF and lone CR to LF.
- Build a comparison key from each line, trimming and/or folding case as selected.
- Keep the first or last line for each distinct key.
- Rejoin the survivors in their original order.
Usage
- Paste the list with duplicates.
- Choose whether to keep the first or last occurrence.
- Run the tool and copy the unique lines.
Examples
These are examples, not current values: they use fixed inputs, while the interactive tool computes live results in your browser.
Keep first
{
"text": "apple\nbanana\napple\ncherry",
"keep": "first",
"caseSensitive": true,
"trim": false
}Keep last
{
"text": "apple\nbanana\napple\ncherry",
"keep": "last",
"caseSensitive": true,
"trim": false
}Case-insensitive
{
"text": "Alpha\nalpha\nBETA\nbeta",
"keep": "first",
"caseSensitive": false,
"trim": false
}Limitations
Deduplicating a list
Line-based de-duplication is useful for log extracts, keyword lists and exports. Deciding whether the first or the last occurrence wins matters when the same key carries different surrounding data.
Frequently asked questions
- What does keeping the last occurrence change?
- The surviving line is the last identical one, so any earlier difference in that line is discarded. Blank lines are compared like any other line.
- Is the comparison affected by trailing spaces?
- Only when trimmed comparison is enabled; otherwise trailing spaces make two lines distinct.
Sources
- ECMA-262: ECMAScript Language Specification — Set — Ecma International
- MDN Web Docs — Set — Mozilla
Send feedback
Tell us if this tool helped, report a problem, or suggest a tool. Only the message you type is sent — never the input you used in the tool.
Was this tool useful?
Prefer to write to us directly? See the contact page.