Skip to content

Remove duplicate lines

Paste a list with one item per line. Each line is kept once, in the place where it first shows up, ready to copy.

Keep
Ignore
Result
More options: compare one column, header line
Compare

Your list stays in this browser. Nothing is uploaded.

Advertisement
A column of paper strips running through a sieve, with the repeated strips caught and set aside

Last checked by the TextEditor.com team

Which copy stays?

By default the tool keeps the first copy of each line in its place and drops the later ones. The order of your list does not change. Excel, Notepad++ and VS Code do the same thing.

When the copies match exactly, keeping the last one only moves the line further down. The choice matters when copies differ a little, for example when you compare one column. Say people signed up twice with the same email address. The last row may hold their new city, so "Last copy" keeps the newest row.

"Only lines with no copy" removes every line that shows up more than once, the first copy too. "Only repeated lines" does the opposite. It lists each repeated line once, so you see what was doubled. To sort the result by number or by length, use sort lines.

Rows compared by the email address
  1. [email protected],Oslo kept
  2. [email protected],Rome kept
  3. [email protected],Bergen removed
  4. [email protected],Lima kept
  5. [email protected],Paris removed
  6. [email protected],Kyiv kept

Pick a choice to see which rows stay.

Why some copies are not found

Two lines only count as copies when every character matches. Some differences are hard to see. A space at the end of a line is invisible. "Milk" and "milk" differ in one letter. Text from a web page often has a no-break space instead of a normal one, and some sites add a zero width space that does not show at all.

The letter é can be stored two ways: as one character, or as e plus an accent mark. Both look the same. Tick "Invisible characters" and the tool treats both forms as one letter. It also skips zero width characters and reads odd spaces as normal spaces.

Files from Windows end each line with two characters, CRLF. Linux and Mac files use one, LF. Join two such files and half the lines carry a hidden carriage return. This tool reads both kinds of line end the same way.

When a looser setting would find more copies, the note under the result says how many. To clean the text itself, use the text cleaner. To see exactly which hidden characters are in a line, paste it into the invisible character tool.

Do these two lines match?

Not the same line. Character 6 differs: line 1 has a space (U+0020), line 2 has a no-break space (U+00A0). They match with Spaces “at the ends and doubled”, Spaces “all spaces” or Invisible characters.

Remove duplicates in Excel and Google Sheets

In Excel, select the column, then go to Data, Data Tools, Remove Duplicates. Pick the columns to compare and click OK. Excel keeps the first copy and deletes the other rows. Press Ctrl+Z if you change your mind.

In our test with Excel for Microsoft 365, Remove Duplicates and the UNIQUE function both ignored case, so "Apple" and "apple" were one value. A space at the end still made a value different. Excel also compares what a cell shows, so one date in two formats counts as two values. See Microsoft's guide to removing duplicate values for the details.

In Google Sheets, select the data and go to Data, Data cleanup, Remove duplicates. Google's help page says cells still count as copies when they differ only in letter case, formatting or formulas. To also catch copies that differ only in spaces, run Data cleanup, Trim whitespace first. Checked November 2026.

Notepad++, VS Code and Word

Notepad++ has Edit, Line Operations, Remove Duplicate Lines. It keeps the first copy of each line anywhere in the file, or in the selected lines. Remove Consecutive Duplicate Lines only removes a copy that sits right below the line it repeats.

In VS Code, press Ctrl+Shift+P and run "Delete Duplicate Lines". With no selection it works on the whole file. It keeps the first copy and compares lines exactly, so case and spaces count.

Word has no command to remove duplicate lines. Home, Sort puts the paragraphs in order, so copies end up next to each other and you can delete them by hand. A wildcard find and replace can also do it, but in our test it removed only one copy per run and paid attention to case. It is quicker to paste the list here and paste the result back into Word.

Checked in the Notepad++ user manual, the VS Code source code and Word for Microsoft 365, November 2026.

Advertisement

Remove duplicate lines on the command line

On Linux and macOS, sort -u sorts the lines and keeps one of each. uniq works another way: it only merges copies that sit right next to each other, so people sort first. Both lose the order of the list. The awk line below keeps the order, because it prints a line only the first time it sees it.

One list, three commands
uniq
  1. pear
  2. apple
  3. pear
  4. Apple
  5. apple
sort -u
  1. Apple
  2. apple
  3. pear
awk '!seen[$0]++'
  1. pear
  2. apple
  3. Apple

sort -u here uses character code order, as with LC_ALL=C. Capital letters come before small ones.

CommandWhat it does
sort -u file.txtSorts and keeps one copy of each line
sort -f -u file.txtThe same, but Apple and apple are one line
awk '!seen[$0]++' file.txtKeeps the first copy, in the original order
tac file.txt | awk '!seen[$0]++' | tacKeeps the last copy, in the original order. macOS has no tac, so use tail -r there.
sort file.txt | uniq -cCounts how often each line appears
sort file.txt | uniq -dShows only repeated lines, once each
sort file.txt | uniq -uShows only lines with no copy
Get-Content file.txt | Select-Object -UniquePowerShell: keeps the first copy in order, case matters
Get-Content file.txt | Sort-Object -UniquePowerShell: sorts and ignores case

A file saved on Windows still has a carriage return at the end of each line. Then sort and uniq see "apple" with and without that character as two different lines, so convert the line ends first. The uniq manual lists more options, like -i to ignore case. Checked with GNU coreutils 8.32 and Windows PowerShell 5.1, November 2026.

Count how often each line appears

The Repeated tab lists every line that has a copy, with how many times it shows up and on which lines. The most common lines come first.

Tick "Show how often" to put the count in front of each line of the result, with a tab after it. Pasted into a spreadsheet, the counts land in a column of their own. Set the order to "most common first" and a list of search terms or error messages becomes a top list.

Duplicates in one column of a table

Rows of a CSV file can differ in one value and still be the same person or product. Open More options, set Compare to "one column" and give its number. The whole row stays or goes, as in Excel. Tick "Keep the first line on top" so the row of column names is left alone.

The tool finds the separator by itself: a tab, a comma, a semicolon or a bar. Values in double quotes may contain the separator. A row that is too short for that column is compared as a whole line. For a grid view of the whole table, open the CSV editor.

Other tools for lists

Frequently asked questions

How do I remove duplicate lines and keep the original order?

Paste the list in the top box. The tool keeps the first copy of each line in its place and removes the later ones, so the order stays as it was.

How do I remove both copies of a duplicate line?

Click "Only lines with no copy" next to Keep. Every line that shows up more than once is removed, the first copy too.

How can I see only the duplicate lines?

Click "Only repeated lines" for one copy of each. The Repeated tab also shows how often each one appears and on which lines.

Why are some duplicate lines not removed?

They differ in a way you cannot see, like case, a space at the end or an invisible character. The note under the result says how many more lines would match with a looser setting. Its button turns that setting on.

Is the comparison case sensitive?

Yes, by default. Tick Case next to Ignore, and Apple and apple count as the same line.

Does it work with very large lists?

Yes. A list of 100,000 lines takes about one to two seconds on a normal computer. Long lists are checked in the background, so the page does not freeze.

Is my list uploaded anywhere?

No. The work happens in your browser. The list is saved only in this browser, so it is still there after a reload.

  • Text editorWrite and edit plain text in your browser.
  • CSV editorOpen a CSV file in a grid, fix cells, sort, add or delete rows and save it as CSV, Excel, JSON or a Markdown table.
  • Word counterCount words, sentences and paragraphs as you type.
  • Case converterPaste text and change it to UPPERCASE, lowercase, Sentence case or Title Case in one click.
  • NotepadKeep several notes in one place.
  • Table editorOpen an Excel or OpenDocument file, or paste cells from a spreadsheet, and edit them in a grid.

↑ ↓ to choose, Enter to open, Esc to close