Toolstia / Remove duplicate lines
Remove duplicate lines from a list
Lists collect duplicates quietly. A mailing list merged from two exports, a set of keywords gathered from several tools, a column of product codes, a log file with repeated errors, a list of URLs to check: all of them end up with the same entry more than once, and counting or sorting by eye does not scale past a few dozen lines.
This tool compares whole lines. In its default mode it keeps the first copy of every line and removes the later ones, in the original order. In the other mode it does the reverse and shows only the lines that appear more than once, each listed a single time, so you can see exactly what repeats.
Options let you decide when two lines count as the same: with or without regard to capital letters, with or without spaces at the ends, and with or without empty lines. A counter reports how many repeats were removed, and how many lines were kept out of the total.
Paste some lines to start.
How it works
- Paste your list, one item per line.
- Choose the options you need.
- Copy the cleaned list.
Which copy is kept
The first time a line appears it is kept, and later copies are removed. With case ignored, "Apple" and "apple" count as the same line and the first spelling you wrote is the one that stays.
Spaces and empty lines
Lines that differ only by a space at the end look identical but are not equal to a computer. Turn on the space option to treat them as the same. Empty lines can be removed too, or one empty line is kept.
Finding what repeats
Switch to "Only the lines that repeat" to see which entries appear more than once. Each repeated line is listed a single time. This is useful for checking mailing lists and keyword lists.
Sorting
Sort A to Z, Z to A or shortest first after the duplicates are gone. Sorting uses your browser's language rules, so accented and Bangla text sorts sensibly.
A worked example with nine lines
Take this list: apple, Apple, a line with a space before apple, banana, apple, two empty lines, cherry, banana. That is nine lines. With the default settings, where upper and lower case are different and spaces are not trimmed, the tool keeps six: apple, Apple, the spaced apple, banana, one empty line and cherry. Three lines were removed, namely the second apple, the second empty line and the second banana.
Now turn off the case option, turn on the space trimming and tick Remove empty lines. The empty lines no longer count, so the total drops to seven, and the result is just apple, banana and cherry: four lines removed, three kept. Switch the mode to show only repeats and the result is apple and banana, with a note that two lines repeat among the seven.
Why lines that look identical are not removed
To a computer, a trailing space, a tab, a different capital letter or a non-breaking space makes a line different. If a duplicate survives, the usual cause is invisible: apple followed by a space is not equal to apple. Turning on the option to ignore spaces at the start and end fixes the most common cases.
The same option also trims the lines you get back, so the kept copy is the cleaned version. When case is ignored, the first spelling you wrote is the one that stays, so Apple at the top beats apple lower down.
Empty lines and the final line break
The text is split at every line break, so a list that ends with a line break has an empty last line, and it counts as a line. Without the empty-line option, one blank line will be kept in the result, which is easy to overlook. If you want a tidy list with no blanks at all, tick Remove empty lines.
Windows and Unix line endings are both understood. Lines that contain only spaces are counted as empty when that option is on, whatever the trim setting.
Sorting after the duplicates are gone
The order choices are original order, A to Z, Z to A and shortest first. Sorting happens after duplicates are removed, so it never changes which copy was kept. A to Z and Z to A use your browser's language rules rather than raw character codes, so accented letters are placed next to their plain versions, and Bangla text is ordered by the browser's own collation.
Shortest first sorts by the number of characters in each line, which helps when you are looking for suspiciously short entries, such as a stray letter in a list of names.
What counts as a duplicate, and what does not
Only complete lines are compared. A line that contains another line, a web address with and without a trailing slash, or two spellings of a name are not duplicates, and neither are lines that differ by a single character. Near-duplicates need a different approach, such as normalizing the text first with find and replace.
For lists where order matters, such as steps in a process, check the result before using it, because removing a repeated line also removes its second position.
Questions
How many lines can it handle?
Tens of thousands of lines work fine on a normal computer.
Does it keep the original order?
Yes, unless you choose a sort order.
Is anything uploaded?
No. Your list stays in your browser and is never sent anywhere.
Does it work with Bangla?
Yes. Any text is compared exactly as written.
Which copy of a repeated line is kept?
The first one. Every later line that matches it is removed, and the remaining lines keep their original order unless you choose a sort.
How do I treat Apple and apple as the same?
Untick the option that says upper and lower case are different. The first spelling in your list is then the one that stays.
How can I find which entries repeat without deleting anything?
Choose the mode that shows only the lines that repeat. Each repeated line is listed once, and the counter tells you how many lines repeat.
Why is there still an empty line in my result?
Blank lines are lines too, and the first one is kept. A list that ends with a line break also has an empty last line. Tick Remove empty lines to drop them.
Does it work on lines with commas or other separators?
It only compares whole lines. If your entries are on one line separated by commas, convert them to one entry per line first.