Duplicate Line Remover

Remove duplicate lines while keeping the first or last occurrence.

  • Runs locally in your browser
  • No upload required

Try it

One item per line; processed entirely in your browser.

Result
alpha beta
Removed
1
Kept
2
alpha
beta

Supported formats

Input
text, select, boolean
Output
text

Privacy

Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.

Processing
In your browser
Privacy level
Browser only

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

  1. Normalise CRLF and lone CR to LF.
  2. Build a comparison key from each line, trimming and/or folding case as selected.
  3. Keep the first or last line for each distinct key.
  4. Rejoin the survivors in their original order.

Usage

  1. Paste the list with duplicates.
  2. Choose whether to keep the first or last occurrence.
  3. 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

jsonSelect to copy
{
  "text": "apple\nbanana\napple\ncherry",
  "keep": "first",
  "caseSensitive": true,
  "trim": false
}

Keep last

jsonSelect to copy
{
  "text": "apple\nbanana\napple\ncherry",
  "keep": "last",
  "caseSensitive": true,
  "trim": false
}

Case-insensitive

jsonSelect to copy
{
  "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

  1. ECMA-262: ECMAScript Language Specification — Set — Ecma International
  2. MDN Web Docs — Set — Mozilla