How to Remove Duplicate Lines from Text (Fast)
Remove duplicate lines from lists, logs, and exports in your browser. Learn when to strip duplicates, when to keep them, and how to avoid mistakes.
Text Tools · UtilityHub Blog
Duplicate lines creep into the most ordinary text: a mailing list copied from two sources, an export where each order appears twice, a log file that repeats the same error, or a to-do list you pasted together over several days. Removing them by hand is slow and easy to get wrong.
This guide shows the fastest way to remove duplicate lines in your browser, the spreadsheet and command-line alternatives, and the cases where deleting duplicates is actually the wrong move.
Clean a list in seconds
Remove duplicate lines from your text and keep only unique lines. Sort output alphabetically if needed.
Why duplicate lines show up in the first place
Most duplicates are not mistakes in the text itself. They come from how the text was assembled:
- Combining two sources. You export a contact list from your CRM and add last month's export on top. Anyone who appears in both is now listed twice.
- Copy-paste overlap. Pasting several sections of a document one after another often repeats headings, notes, or shared items.
- Exports that repeat parent rows. Order systems frequently print the order ID on every line item, so the ID repeats for each product.
- Log files. Repeating errors stack up line by line during a long run.
- Manual entry. A list typed over several sessions tends to collect the same item twice under slightly different spacing.
Knowing the source matters because it tells you what kind of duplicate to expect - and whether the right fix is a one-click cleanup or a smarter comparison.
Exact duplicates vs near-duplicates
Not every duplicate looks identical. It helps to separate two cases before you clean anything.
Exact duplicates are byte-for-byte the same: same spelling, same capitalisation, same spacing. These are safe to collapse automatically.
Near-duplicates differ by a detail that looks irrelevant to a human but not to a computer:
| Pair | Why it is not an exact match |
|---|---|
Apple / apple | Different capitalisation |
apple / apple | Trailing space |
New York / New York | Extra whitespace |
john@site.com / John@site.com | Mixed case in an email |
If your list came from a spreadsheet, a form, or several people typing, expect near-duplicates. Cleaning spaces and case first makes the duplicate removal far more accurate.
Method 1: the browser duplicate line remover
This is the fastest route for a one-off cleanup and needs no install.
- Open the Duplicate Line Remover.
- Paste your list into the input box - one item per line.
- Choose how to compare:
- Preserve order keeps each line where it first appeared.
- Sorted output returns an alphabetical list instead.
- Case-insensitive treats
Appleandappleas the same entry and trims spaces before comparing.
- Click the remove button.
- Copy the cleaned output back into your spreadsheet, document, or message.
The tool keeps the first occurrence of each line and removes later copies. That is usually what you want: the first entry is the one you wrote first, before the list started repeating itself.
A worked example
Input:
apples
bananas
Apples
bananas
cherries
With exact matching and preserve order, the output is:
apples
bananas
Apples
cherries
Apples survives because the capital A makes it a different line. bananas appears once. Now switch case-insensitive mode on and the output becomes:
apples
bananas
cherries
The first spelling wins, which is why checking the input for inconsistent capitalisation is worth the extra minute.
Method 2: remove duplicates in a spreadsheet
If your data already lives in Excel, Google Sheets, or a similar tool, you can deduplicate there without moving it.
Google Sheets: select the column, open Data > Data cleanup > Remove duplicates, then confirm. Sheets tells you how many rows were removed.
Excel: select the range, go to Data > Remove Duplicates, tick the columns that define a duplicate, and confirm. Excel reports how many values were removed and how many remain.
Both tools compare the selected cells exactly. Trailing spaces and capitalisation differences count as unique, so use TRIM() on a helper column when your source is messy, then deduplicate the cleaned column.
When the spreadsheet is the better choice
Use the spreadsheet rather than the text tool when:
- You need to deduplicate one column while keeping the rest of the row intact.
- You want a record of how many rows were removed.
- The file has thousands of rows and you will reuse the process next month.
Use the text tool when the list is a plain block of text, when you do not want to open a spreadsheet, or when you need a quick one-off cleanup on a phone.
Method 3: command line, for repeatable jobs
If you clean lists often, a command is worth memorising. On macOS or Linux:
sort -u input.txt > output.txt
This sorts the lines and removes exact duplicates in one step. If you need to preserve the original order, use a tool such as awk '!seen[$0]++' input.txt.
On Windows PowerShell:
Get-Content input.txt | Sort-Object -Unique | Set-Content output.txt
The command-line route is ideal for scheduled or large jobs, but it is less forgiving: one stray space and the duplicates survive. That is the same failure mode as the exact-match option in the browser tool, just harder to spot.
Clean the text before you deduplicate
A few quick prep steps make any method more reliable:
- Trim spaces. Remove leading and trailing spaces so that invisible whitespace does not create phantom duplicates.
- Normalise case if capitalisation is not meaningful for your data.
- Split merged lines. If several items were pasted onto one line, split them onto separate lines first so each can be compared.
- Check for empty lines. Blank lines duplicate just as easily; remove them after deduplicating.
- Spot-check the result. Compare the before and after counts to make sure you removed the number you expected.
You can trim extra spaces with the Remove Extra Spaces tool and check the final size with the Word Counter or Character Counter - useful if the cleaned list has a length limit.
When you should NOT remove duplicates
Removing duplicates is not always correct. Keep them when the repetition carries information:
- Order and invoice lines. The same product can legitimately appear twice; the quantity matters.
- Logs and audit trails. A repeated error at 10:00 and 11:00 is a pattern, not noise.
- Votes, reactions, and counts. One entry per event is the data.
- Survey answers. Two people can give the same answer and both count.
- Sequential records. Timestamps or IDs usually make each line unique anyway.
A simple test: if deleting the second copy loses a fact, do not delete it. Deduplication is for lists where each line is supposed to represent one unique item - names, emails, URLs, tags, or product codes.
Privacy: what happens to your text
The browser tool processes everything locally. The text is read in the page, deduplicated in memory, and returned to you; it is not uploaded to a server or stored in an account.
That said, local processing is not a licence to paste anything. If you are cleaning a customer export, strip card numbers, passwords, and other sensitive fields first. If the list contains personal data, treat the whole exercise as handling personal data - even when the tool is private.
Quick checklist
- Know whether you are dealing with exact or near-duplicates.
- Decide upfront whether capitalisation matters.
- Trim spaces before comparing.
- Keep first occurrences unless you have a reason to keep the last.
- Save a copy of the original list before you overwrite it.
- Do not deduplicate data where repetition is the information.
Paste your list and clean it now
Remove duplicate lines from your text and keep only unique lines. Sort output alphabetically if needed.
Related reading: if you are preparing text for publication, see how to count characters for social media and use a character counter to match platform limits. For messy formatting in general, the case converter guide explains how to normalise capitalisation before you compare lines.