Duplicate Line Remover
Published Updated
Keep the first copy of each line and drop the rest, with switches for case, edge spaces, sorting and blank lines. Matching ignores case and edge spaces by default, so Apple, apple and ' APPLE ' count as one, and the first is kept as written.
The four switches
| Switch | Default | Effect |
|---|---|---|
| Case sensitive | Off | Off: Apple and apple match. On: they are different lines. |
| Trim whitespace | On | Spaces, tabs, no-break spaces and other Unicode spaces at either end are ignored when matching, and kept in the output. A zero-width space is not trimmed. |
| Sort alphabetically | Off | Sorts the survivors with the browser's locale comparison. |
| Remove blank lines | Off | Drops whitespace-only lines before the check and counts them. |
A worked example
The input has seven lines: Apple, apple, a line of spaces around APPLE, Pear, two empty lines and Pear again. With the defaults, the output is Apple, Pear and one empty line. The summary reads 7 total, 3 unique and 4 duplicates removed. Turn on Remove blank lines and the empty entry goes as well.
How the counts are made
Total Lines is every line in the box, including blank ones. Duplicates Removed counts every repeat that was dropped, and while Remove blank lines is off that includes repeated empty lines: in the worked example the 4 are apple, APPLE, the second empty line and the second Pear. With the switch on, empty and whitespace-only lines are counted under Blank Lines Removed instead, and the same example reads 7 total, 2 unique, 3 duplicates removed and 2 blank lines removed. Unique Lines is the number of rows in the output, so a blank line that survived is counted as one.
Which lines count as the same
With Case-sensitive matching off, each line is lowercased before it is compared. We ran these lists through this page's tool in Google Chrome 157, Firefox 155 and Playwright's WebKit build (not the Safari app), with the other switches at their defaults. All three kept the same lines:
| Lines pasted | Lines kept | Why |
|---|---|---|
| STRASSE, straße | Both | STRASSE lowercases to strasse, which is not straße. |
| İSTANBUL, istanbul | Both | İ lowercases to i plus a combining dot, so the keys differ. |
| ISTANBUL, istanbul | ISTANBUL | A plain I lowercases to i. |
| ıstanbul, ISTANBUL | Both | The dotless ı stays ı. |
| ΟΔΟΣ, οδος, οδοσ | ΟΔΟΣ and οδοσ | A capital Σ at the end of a word lowercases to the final ς, which matches οδος but not οδοσ. |
| ΆΛΦΑ, άλφα | ΆΛΦΑ | Accented Greek capitals match their small letters. |
| DŽungla, Džungla, džungla | DŽungla | All three forms of the dž letter lowercase to dž. |
| file (with the fi ligature), FILE, file | file and FILE | The ligature stays one character when lowercased, so it never matches f plus i. |
| café (é as one character), café (e plus a combining accent) | Both | No Unicode normalization is applied. |
| Kelvin written with the Kelvin sign K (U+212A), kelvin | The first | The Kelvin sign lowercases to an ordinary k. |
Trim whitespace is checked the same way. Ten lines, eight versions of apple with a different character at one end plus a b written with one space and with two, were reduced to 4 with trimming on: a space, a tab, a no-break space, an ideographic space (U+3000), a byte order mark (U+FEFF) and a line separator (U+2028) were all ignored, but apple followed by a zero-width space (U+200B) stayed separate, and so did a b with two spaces in the middle. With trimming off, all 10 lines stayed.
Empty lines and the counters
Results from the same three browsers. In the first column, "empty" is a line with nothing on it:
| Lines pasted | Switches changed | Result | Total / Unique / Duplicates Removed / Blank Lines Removed |
|---|---|---|---|
| a, empty, b, three spaces, a tab, a, and a final line break | None | a, an empty line, b | 7 / 3 / 4 / 0 |
| The same | Remove blank lines on | a, b | 7 / 2 / 1 / 4 |
| a, empty, three spaces, a tab, three spaces, and a final line break | Trim whitespace off | a, an empty line, three spaces, a tab | 6 / 4 / 2 / 0 |
| a and b with Windows (CR LF), plain (LF) and old Mac (CR) line breaks: a, b, a, b, final line break | None | a, b, an empty line | 5 / 3 / 2 / 0 |
With trimming on, a line of spaces or a tab counts as a repeat of the first empty line. A final line break adds an empty last line, and it stays in the result as one empty row until Remove blank lines is switched on.
The order Sort alphabetically gives
Sorting uses the browser's own language rules, and all three browsers, each set to English, gave this order for a mixed test list (Case-sensitive matching on, so a and A both stay):
_x -y (note) #tag 10 100 2 9 a A ä Ä Apfel Äpfel apple b B e é eclair éclair i I İ ı n ñ nz o ø oe œ ss ß st x10 x2 z Z Zebra ω Ω Ж 日本
Punctuation comes first and numbers are compared as text, so 10 and 100 come before 2, and x10 before x2. A small letter comes before its capital, accented letters sit next to their plain forms, and Greek, Cyrillic and Chinese follow the Latin letters. For a numeric order, Sort Lines Alphabetically has a Numeric mode.
How long a big list takes
Generated lists of lines such as golf 41873, about 6% of them repeats, pasted into an empty box. Time until the result box and counters were updated, median of 5 runs on one computer:
| List and action | Chrome 157 | Firefox 155 | WebKit build |
|---|---|---|---|
| 100,000 lines (1,190,407 characters), pasted | 865 ms | 342 ms | 555 ms |
| The same, pasted with Sort alphabetically on | 853 ms | 434 ms | 577 ms |
| The same, switching Sort alphabetically on | 535 ms | 296 ms | 124 ms |
| 1,000,000 lines (12,904,398 characters), pasted | 12,549 ms | 4,126 ms | 6,313 ms |
| The same, pasted with Sort alphabetically on | 14,523 ms | 5,945 ms | 6,960 ms |
| The same, switching Sort alphabetically on | 11,388 ms | 4,164 ms | 2,742 ms |
The duplicate check itself took 361 ms in Chrome 157, 464 ms in Firefox 155 and 360 ms in the WebKit build on the million-line list (1,057, 1,816 and 904 ms with sorting), so most of the page time is spent outside the check itself. The result for that list: 1,000,000 total, 939,795 unique, 60,205 duplicates removed.
Removing duplicates
Step 1
Paste the list
One entry per line. Line endings from Windows or old Mac files are converted to plain line feeds.
Step 2
Set the switches
Case sensitive is off and Trim whitespace is on by default. Sort alphabetically and Remove blank lines start off.
Step 3
Copy Result
The counts above the output show total lines, unique lines, duplicates removed and blank lines removed.
Edge cases
- A trailing newline makes the line count one higher than the visible rows.
- Lines that differ only by canonical equivalence, as MDN's normalize reference describes for ñ written two ways, are kept apart.
- Windows files with CRLF come back with LF only.
- Case folding is a plain lower-casing, so STRASSE and straße stay apart.
- For a different order, Sort Lines Alphabetically sorts without removing anything, and Remove Empty Lines handles blanks and indentation.
Duplicate line questions
Which copy of a duplicate is kept?
The first one, exactly as you wrote it. Matching uses a lower-cased and trimmed key, but the output line keeps its own spacing and capitals. Of Apple, apple and ' APPLE ', the line Apple survives.
Why do two identical-looking lines both stay?
They are different strings. A composed é and an e followed by a combining accent look alike and are canonically equivalent according to MDN's String.normalize page, but this page applies no normalization. The same goes for STRASSE and straße.
Why is there a blank line in my result?
A trailing newline adds an empty last line, and the first empty line survives as a unique entry. Switch on Remove blank lines to drop them all.
Does sorting change which line is kept?
No. Duplicates are removed first, then the survivors are sorted with the browser's locale rules. The sort is case-aware, so Ä lands between a and b in an English browser.
Can it find lines that are only similar?
No. Lines must match completely after trimming and case folding. Compare Text shows differences between two blocks, and nothing here does fuzzy matching.
Is my list uploaded?
No. The list is processed in your browser by this page's JavaScript; this page does not upload it. A set in the page's memory tracks the lines already seen.
Why are İSTANBUL and istanbul kept as two lines?
Matching lowercases each line with no language setting, and İ lowercases to i plus a combining dot, so the two keys differ. ISTANBUL and istanbul do match. STRASSE and straße stay apart for a similar reason. Chrome 157, Firefox 155 and the WebKit build kept the same lines.
Does Trim whitespace remove no-break spaces?
Yes, for matching. A no-break space, a tab, an ideographic space, a byte order mark and a line separator at either end were all ignored, so those lines matched a plain apple. A zero-width space was not ignored. The line you keep still shows its original characters.
Why does 10 come before 2 when I sort?
Sort alphabetically compares lines as text, so 10 and 100 sort before 2 and 9, and x10 before x2, in all three browsers tested. Use the Numeric mode of Sort Lines Alphabetically when the numbers matter.
Can it handle a list of a million lines?
Yes, with a wait. A generated list of 1,000,000 lines (12.9 million characters) took 12.5 s in Chrome 157, 4.1 s in Firefox 155 and 6.3 s in the WebKit build to show its result, median of 5 runs. A list of 100,000 lines took 0.3 to 0.9 s.