Text Tools

Remove Duplicate Lines

Remove repeated lines from a list and keep each line once.

Browser workspace
LOCAL PROCESSING

Input stays in this browser while you use the tool.

About this tool

The Remove Duplicate Lines tool takes a list with one item on each line and returns the same list with every repeated line removed, so that each line appears only once. It is made for the jobs where a text file, a spreadsheet column or a log has grown by copy and paste: email lists, keyword lists, URLs, product codes, hostnames, usernames and error messages.

The rule is simple. Two lines are duplicates when they are exactly the same, character for character. The tool keeps the first copy of every line and drops the later copies, and the remaining lines stay in their original order. That order is useful, because the first occurrence is often the one that matters, such as the first time an error appeared in a log or the first entry of a ranked list.

The words "exactly the same" are the part that needs care. A line with a space at the end is a different line from the same line without it. A capital letter makes a line different from its lowercase twin. Lines that end in a Windows line break are not the same as lines that end in a Linux line break, and two characters that look identical on screen can still be different characters. Many surprises with duplicate removal come from these invisible differences, and the common errors below show how to spot them.

The tool compares whole lines. It does not look at words inside a line or at a single column of a CSV file. The work runs in your browser, so your list is processed on your own device and is not sent to the BitToolsKit server.

Use cases

  • Clean an email or contact list. Merge lists from several sources and remove addresses that appear more than once, so that nobody receives a message twice.
  • Tidy a keyword or tag list. SEO keyword exports, product tags and search terms often contain the same entry many times.
  • Prepare a list of URLs. Remove repeated addresses before you check links, build a sitemap or crawl a set of pages.
  • Shrink a log file excerpt. When the same error line repeats hundreds of times, the distinct messages are easier to read.
  • Merge configuration or hosts files. Combine two lists of hostnames, IP addresses or domains and keep each entry once.
  • Deduplicate a column copied from a spreadsheet. Copy one column, paste it here and get the distinct values.
  • Prepare unique values for code. Build a list of distinct IDs, codes or names before you paste it into a script, a SQL IN list or a test.
  • Compare two lists. Remove duplicates from each list first, then use the Text Diff Checker to see which lines differ.

How to use

  1. Paste your list into the Input box, with one item on each line.
  2. If the tool offers options, choose how lines should be compared. Typical choices are whether capital letters count as a difference, whether spaces at the start and end of a line are ignored, and whether empty lines are kept.
  3. Click Run tool.
  4. Read the list in the Output box. Every line appears once, in the order of its first occurrence. Compare the number of lines before and after to see how many duplicates were removed.
  5. If lines that look the same are still repeated, check the common errors below for invisible differences such as a trailing space, a tab or a different line ending.
  6. Click Copy output to copy the list, Download to save it as a file, or Clear to start again.

If you want to count how many lines a list has before and after, the Word Counter shows the number of lines, words and characters. To make capital letters consistent before you compare, run the list through the Case Converter first.

Examples

Example 1: A simple list

Input:
apple
banana
apple
cherry
banana
apple
What the tool produces:
apple
banana
cherry
Six lines became three. Three duplicate lines were removed, and the first copy of each line was kept in its original order.

Example 2: Which copy is kept

Input:
error: disk full
warning: low memory
error: disk full
ok
What the tool produces:
error: disk full
warning: low memory
ok
The first occurrence stays where it was, and the later copy is dropped. A sorted list would put the lines in a different order, so check whether your tool sorts.

Example 3: Capital letters

Input:
Apple
apple
APPLE
Banana
Comparing exactly (case-sensitive):
Apple
apple
APPLE
Banana

Ignoring case:
Apple
Banana
Ignoring case keeps the first spelling that it meets.

Example 4: Lines that look the same but are not

Input (visible as four lines of apple):
apple
apple(space at the end)
(space at the start)apple
apple(tab at the end)
Comparing exactly:
All four lines are kept, because each one is a different string.

Ignoring spaces at the start and the end:
apple
The tab at the end counts as white space too, but a space inside the line would not.

Example 5: Empty lines

Input:
a

b


a
What the tool can produce:
a
(empty line)
b
The repeated empty lines count as duplicates, so one empty line stays. Remove empty lines first, or turn on the option that drops them, if you want a list without any.

Example 6: Email addresses

Input:
Ada@Example.com
ada@example.com
bob@example.com
Comparing exactly: three lines.
Ignoring case: two lines (Ada@Example.com and bob@example.com).
Most mail providers treat the two spellings of an address as the same mailbox, so ignoring case is usually the right choice for email lists.

Example 7: Web addresses

Input:
https://example.com/page
https://example.com/page/
https://example.com/page
What the tool produces:
https://example.com/page
https://example.com/page/
The address with the slash at the end is a different line. The tool compares text, not meaning.

Example 8: Numbers

Input:
1
01
1.0
1
What the tool produces:
1
01
1.0
The lines are compared as text, so 1, 01 and 1.0 are three different lines even though they have the same value.

Example 9: A non-breaking space

Input:
price 5
price(non-breaking space)5
What the tool produces:
Both lines are kept. A non-breaking space (U+00A0) looks like a normal space, but it is a different character, so the two lines are not identical.

Example 10: Counting the repeats

Input:
apple
banana
apple
cherry
banana
apple
If you need the counts instead of a shorter list:
apple 3
banana 2
cherry 1
The command sort file.txt piped to uniq -c prints the same counts on the command line.

Common errors

Lines that look the same are not removed

They differ in a way that you cannot see. The usual causes are a space or a tab at the end of a line, a space at the start, a different capital letter, or a non-breaking space. Turn on the option that ignores spaces at the start and the end, or clean the list first and run the tool again.

Lines with Windows line endings stay as duplicates

A file written on Windows ends its lines with a carriage return and a line feed. If a tool splits only at the line feed, the line a followed by a carriage return is not equal to a at the end of the file, which has none. Convert the line endings so that they are all the same, or paste the text again from one source.

Two spellings in capital and small letters stay in the list

The comparison is exact by default, so Apple and apple are different lines. Choose the option that ignores case, or make the case consistent with the Case Converter before you remove the duplicates.

The result lost a line that you wanted to keep

Ignoring case or spaces merges lines that you may want to keep apart, for example IDs that are case-sensitive, Linux file paths or passwords. Compare exactly when capital letters and spaces carry meaning, and keep a copy of the original list.

The order of the lines changed

Removing duplicates keeps the order of the first occurrences. If the output is sorted, you used an option or a command that sorts first. On the command line, sort and uniq give a sorted result, while awk with the test !seen[$0]++ keeps the original order.

Values such as 1, 01 and 1.0 are all kept

The lines are compared as text and not as numbers. Make the formatting the same first, for example by removing leading zeros, and then remove the duplicates.

Web addresses or email addresses are not treated as the same

A slash at the end, http instead of https, a www prefix or capital letters in the address make the text different. Normalise the addresses first, because the tool cannot know that two of them lead to the same page.

Accented letters that look the same stay as two lines

The same letter can be stored in two ways: as one precomposed character or as a letter plus a combining accent. They look identical, but they are different characters. In a test, Café written in both forms stayed as two lines until the text was normalised to one form.

An invisible character makes lines different

A zero-width space, a byte order mark or another invisible character at the end of a line makes it a different line, although it looks the same. Check the bytes of the suspicious lines with the Text to Binary / Hex Converter, or retype one of the lines.

The tool does not remove duplicates inside a line or in a column

It compares whole lines. A repeated word inside a line, or a repeated value in one column of a CSV file, is not touched. Copy the column into the tool, or split the text so that each item is on its own line.

Frequently asked questions

How does the tool decide that two lines are duplicates?

Two lines are duplicates when they are exactly the same, character by character. A different capital letter, an extra space or a different line ending makes them different, unless the tool offers an option that ignores that difference.

Which copy of a repeated line is kept?

The first one. Later copies are removed, and the remaining lines stay in the order in which they first appeared.

Does the tool change the order of my lines?

Removing duplicates alone does not. The order of the first occurrences is kept. If your tool also offers to sort the lines, that is a separate option that changes the order.

Is the comparison case-sensitive?

By default, yes, so Apple and apple are different lines. If the tool has an option to ignore case, turn it on when capital letters do not matter, as in most email lists.

How do I remove duplicate lines on the command line?

On Linux and macOS, sort -u file.txt gives the distinct lines in sorted order. To keep the original order, use awk '!seen[$0]++' file.txt. The command uniq alone removes only duplicates that are next to each other, which is why it is usually combined with sort.

How do I keep only the lines that appear once, or only the repeated ones?

With the command line, sort file.txt piped to uniq -u shows the lines that appear once, and uniq -d shows one copy of each repeated line. In code, you can count the lines and filter by the count.

Can I remove duplicates in JavaScript or Python?

Yes. In JavaScript, new Set(lines) keeps the first occurrence of each line in order, and Array.from turns it back into an array. In Python, dict.fromkeys(lines) does the same and keeps the order.

Does the tool remove empty lines?

Repeated empty lines count as duplicates, so only one empty line remains, unless the tool offers an option to drop empty lines. If you want a list with no empty lines at all, remove them first.

Can I remove duplicates by one column of a CSV file?

Not with this tool. It compares whole lines. Copy the column you care about into the input, or use a spreadsheet or a script that works on columns.

Is my list uploaded to a server?

No. The tool runs in your browser and works on your device. As a general habit, avoid pasting passwords, API keys or private tokens into any online tool.

Related tools

Share this page