Remove duplicate lines
How to remove duplicate lines from a list
- Paste your list into the first box, one item per line, or open a .txt, .csv, .log or .md file.
- Set the options: Case sensitive, Trim spaces, Remove empty lines, and Keep first or last. The result updates a moment after each change.
- Read the line under the result, for example 8 lines in, 3 removed, 5 left.
- Press Copy result, or Download .txt to save it as unique-lines.txt.
- Press Clear to start another list.
What counts as the same line
Two lines are the same when their text matches exactly. With the defaults, alpha and Alpha are different, and so are alpha and alpha with a space at the end. We used a small list of 8 lines to test each option: alpha, Beta, alpha, an empty line, beta, Alpha (with a trailing space), alpha and another empty line.
- Defaults (case matters, keep first): 3 removed, 5 left. The output was
alpha,Beta, an empty line,beta,Alpha. - Case sensitive off: 4 removed, 4 left, because
betanow matchesBeta, whileAlphawith its trailing space still differs fromalpha. - Trim spaces: the line
Alphaloses its space and is written asAlpha. - Case off and trim on: 5 removed, 3 left (
alpha,Beta, an empty line). - Remove empty lines added: 6 removed, 2 left.
Empty lines are lines. By default the first one stays and later ones go,. Tick Remove empty lines to drop them all.
Keep first, keep last, or keep only the lines that occur once
Keep first leaves each line where it first appeared. Keep last leaves it where it last appeared, so the list is in the order of the last copies: our test gave Beta, beta, Alpha , alpha and an empty line.
The option Remove every line that appears more than once is different. It deletes all copies, so only lines that were never repeated survive. On our list that left Beta, beta and Alpha (5 removed). With case off and trim on, every line had a twin and the result was empty. This option overrides Keep first or last: a, b, a gave just b with Keep last selected.
Sort puts the result in order after the duplicates are gone. A to Z reads digits as numbers, so item1, item2, item10 come out in that order. With case sensitive on, lowercase sorts before uppercase (a, A, b, B). Z to A reverses it.
Accents, other scripts and invisible characters
The comparison uses Unicode normalization, so café typed with a single é and café typed as e plus a combining accent count as one line. The first form is the one kept.
Ignoring case lowercases both lines, which is simple and not full case folding. Straße and STRASSE stayed as two lines, and so did a Turkish İ and i. A zero-width space makes a line different, and you cannot see it. Trim removes spaces, tabs and no-break spaces, but not zero-width characters.
A single line break at the end of the text is not counted as a line: a, b, a followed by one line break is 3 lines. Two line breaks leave one empty line. The output has no line break at the end.
Windows line breaks (CRLF) are not kept. A file we opened with CRLF came out of the download with plain LF.
Large lists
We pasted generated lists into headless Chromium 158 and timed the result, 120 ms typing delay included. 100,000 lines (1.8 MB) took 1.0 second. 200,000 lines (3.6 MB) took 2.2 seconds, and 200,000 lines that were all different took 3.0 seconds. 1,000,000 lines (17.9 MB) took 8.4 seconds and gave the right count. Sorting the 100,000 lines left from the 200,000-line list took 0.1 second.
A file over 20 MB is refused with a message. We did not test pasted text above 17.9 MB.
Where your list goes
We opened the page with outside connections blocked and typed a list that held a unique marker string, then copied the result. Of 12 requests, 2 went to outside scripts (the Google ad script and tag), which we blocked, so we cannot say what they would send. No request carried a body or the marker, and localStorage and sessionStorage held no keys.
Other text tools
To count what is left, use the word counter. To change capitals before you compare, try the case converter. For a table, CSV to JSON keeps the columns apart.
Measured results
| Option | What we ran | What came out |
|---|---|---|
| Defaults | 8 lines | 3 removed, 5 left |
| Case off | 8 lines | 4 removed, 4 left |
| Case off, trim on | 8 lines | 5 removed, 3 left |
| Keep last | 8 lines | 3 removed, 5 left, last copies in their order |
| Only lines that occur once | 8 lines | 5 removed, 3 left |
| Defaults | 200,000 lines, 100,000 different | 100,000 left in 2.2 s |
| Defaults | 1,000,000 lines, 100,000 different | 100,000 left in 8.4 s |
Prefer desktop software?
Notepad++ has Remove Duplicate Lines under Edit, Line Operations, and on Linux and macOS sort -u removes duplicates from a file. They suit very large files or a repeating job. We did not test either, so how they treat case, spaces and accents may differ from this page.
Frequently asked questions
Does this page upload my list?
No. The work happens in your browser and no request carries your text. In our test with outside connections blocked, no request had a body and none contained our marker string.
Can I keep the last copy instead of the first?
Yes. Choose Last occurrence in the Keep list. The result is then in the order of the last copies.
How do I remove duplicates but ignore capital letters?
Untick Case sensitive. alpha and Alpha then count as one line, and the first one is kept.
Why was a line with a trailing space not removed?
Because a space makes the line different. Tick Trim spaces to compare and write the lines without spaces at the start and end.
How do I keep only the lines that appear once?
Tick Remove every line that appears more than once. All copies of a repeated line are deleted, including the first.
Does it keep the original order?
Yes, unless you choose a sort. With Keep last, the order follows the last copy of each line.
Does it work on CSV rows?
It compares whole lines, so two rows match only if every column is the same. It does not look at one column. Windows line breaks in a file become plain line breaks.
How many lines can it handle?
We tested up to 1,000,000 lines (17.9 MB), which took 8.4 seconds. A file over 20 MB is refused when opened.