Notepad++

How to Remove Duplicate Lines in Notepad++ (Sorted or Unsorted)

How to Remove Duplicate Lines in Notepad++ (Sorted or Unsorted)

Notepad++ has a built-in command for this. Go to Edit > Line Operations, click Remove Duplicate Lines, and every repeated line disappears while the first instance of each stays.

It wasn’t the first duplicate command to ship, though. Version 7.6.4 added Remove Consecutive Duplicate Lines on March 6, 2019, and the change log says it removes consecutive duplicates only, across the whole document (Notepad++ project change log, GitHub, 2019).

If your duplicates are scattered around a list, you need the whole-document command, a sort before the consecutive one, or a regular expression in the Replace dialog.

How to remove duplicate lines with the Line Operations menu

YouTube player

Everything lives in the Edit menu under Line Operations. No plugin is involved, and a Notepad++ community thread on a December 2024 build confirms the command sits in the same submenu as Remove Consecutive Duplicate Lines.

  1. Open the file in Notepad++, or paste the list into a new tab.
  2. Press Ctrl+A to select all text, or highlight only the lines you want cleaned.
  3. Go to Edit > Line Operations.
  4. Click Remove Duplicate Lines.
  5. Compare the line total on the status bar with the figure from before the run.

What stays in the file

The first occurrence of each line stays right where it was. Every later repeat goes, wherever it sits, and lines that only appear once are left alone.

Because the first instance survives, what remains keeps the order of the original file. That’s the main reason to try this command before any sort-based method.

Running the command on a selection

Highlighting a block first limits the cleanup to those lines, which suits a CSV export where the header row should stay out of the comparison.

Selection handling hasn’t been consistent across releases. In 2019 builds the consecutive command ignored the selection and processed the whole file (Notepad++ community).

Run it on a copy first when the file matters, and confirm the scope with the line total afterward.

Remove Duplicate Lines vs Remove Consecutive Duplicate Lines

The whole-document command checks every line against all the others. The consecutive one only looks at the line directly above, so a repeat further down goes unnoticed.

BehaviorRemove Duplicate LinesRemove Consecutive Duplicate Lines
ScopeEntire documentAdjacent lines only
Line keptFirst occurrenceFirst line of each run
Sort needed firstNoYes, for scattered duplicates

Why guides contradict each other

A forum thread on the upcoming 7.6.4 release called the new command Remove Duplicate Lines and noted it removed only neighboring duplicates (Notepad++ community). It shipped in 2019 as Remove Consecutive Duplicate Lines.

Later builds list both entries under Edit > Line Operations, as a thread on a December 2024 build shows (Notepad++ community).

So any guide that calls Remove Duplicate Lines adjacent-only is describing the 2019 command. If your menu shows just the consecutive entry, your build is likely older than the whole-document command.

Blank lines count as duplicates too

Remove Consecutive Duplicate Lines also collapses runs of blank lines.

A block of several empty lines shrinks to one, which guy038 pointed out when 7.6.4 was released (Notepad++ community). If you’d rather delete them outright, Remove Empty Lines and Remove Empty Lines (Containing Blank characters) do that.

New to Notepad++ or just need a quick reference? Essential shortcuts, regex for Find & Replace, and advanced editing - including Ctrl+H, Column Mode, and Macro Recorder - is on one page in the Notepad++ Cheat Sheet.

How to remove duplicates after sorting the lines

YouTube player

Sorting puts identical lines next to each other, and that’s the one condition Remove Consecutive Duplicate Lines needs.

  1. Go to Edit > Line Operations > Sort Lines Lexicographically Ascending.
  2. Go to Edit > Line Operations > Remove Consecutive Duplicate Lines.
  3. Compare the status bar line total before and after.

This was the standard forum answer by early 2020: sort first, then run the consecutive command (Notepad++ community).

The cost is the original order, and Ctrl+Z is the only way back. A sorted dedupe fits email lists and keyword lists, where sequence carries no meaning.

If order matters, skip this route and use the whole-document command or the regex method with a reverse step.

Choosing a sort command

The lexicographic sorts come in ascending and descending versions, each with an ignoring-case twin. Notepad++ also offers locale, integer, decimal and by-length sorts, but none of them helps here.

Plain sorts compare character code points, so uppercase letters sort before lowercase (guy038, Notepad++ community).

The ignoring-case versions fold only ASCII letters, which means an accented capital stays apart from its lowercase form (Mark Olson, Notepad++ community, 2023).

For removal, direction doesn’t matter. Only grouping does, so either plain sort is enough.

Removing duplicate lines with a regular expression

A regular expression does the job from the Replace dialog. Press Ctrl+H, set Search Mode to Regular expression, paste the pattern into Find what, and click Replace All.

On a sorted file, use (?-s)^(.+\R)\1+ with \1 in Replace with. Each run of identical lines collapses into one (guy038, Notepad++ community).

On an unsorted file, use (?-s)^(.+\R)(?=(?s:.*)^\1) and leave Replace with empty. That removes every earlier copy and keeps the last one (guy038, Notepad++ community).

Add a line break after the last line first, because both patterns expect every line to end with one.

Keeping the first occurrence in the original order

The unsorted pattern keeps the last copy, so the workaround is to feed it a reversed file.

  1. Reverse the line order (Sofistanpp named the Reverse Lines plugin for this; current builds also have Edit > Line Operations > Reverse Line Order).
  2. Run the unsorted pattern with an empty Replace with.
  3. Reverse the lines again.

The last copy in the reversed file is the first copy in the original, so the second reversal restores the sequence with first occurrences kept (Sofistanpp, Notepad++ community).

Searching backward with a regex isn’t a shortcut. Notepad++ discourages it and partly disables it.

Line endings inside the pattern

\R matches \r\n, \n or \r, so one pattern works on Windows files and on the Unix and old Mac kinds too (guy038, Notepad++ community).

The status bar shows the current file’s line ending type: Windows (CR LF), Unix (LF) or Macintosh (CR) (PeterJones, Notepad++ community).

A file with mixed endings breaks the match, and it’s a common reason a dedupe misses lines.

Why does Notepad++ leave duplicates or delete too much?

Most misses come from differences you can’t see on screen: line endings, trailing spaces, letter case and a missing final line break. Over-deletion is rarer and tied to very large files.

Differences that hide on screen

Two lines that look identical stay separate the moment one invisible character differs.

  • A CRLF line and an LF line with the same text aren’t true duplicates (Alan Kilborn, Notepad++ community). The status bar shows the file’s ending, and Edit > EOL Conversion unifies it.
  • One extra space at the end of a copy makes it a different line, so run Edit > Blank Operations > Trim Trailing Space before the removal (guy038, Notepad++ community).
  • ABC, AbC and abc survive as separate lines. A community member who read the command’s behavior described the compare as case-sensitive and sensitive to the line ending, so confirm on a copy.
  • A last line with no break at the end may not match an earlier identical line that has one.

Users have reported Remove Duplicate Lines sometimes removing nothing at all. Line endings were the first suspect named in that thread (Notepad++ community).

Regex limits on large files

guy038 put the failure point of the keep-last regex at files over about 10 MB, or at duplicates more than about 10,000 lines apart (Notepad++ community, 2020).

A later thread on version 8.6.7 gave different cutoffs for duplicate-marking patterns, from about 1,600 to about 15,000 in-between lines, and an Invalid Regular Expression error past about 12,000 lines in one test.

The figures disagree because the limit is a complexity cap in Boost.regex, not a fixed line count. The cutoff moves with the pattern and the data.

Splitting the file helps. Run the pattern on each part, merge them, and run it once more on the whole. You can also click Replace one match at a time instead of Replace All, and stop if a single replacement wipes the file.

When the consecutive command removes too much

A user with 5.3-million-record files reported that both his regex and the built-in Remove Consecutive Duplicate Lines deleted every record after the last duplicate found.

Alan Kilborn pointed out that the built-in command is itself a regex replacement written in C++, so the same outcome made sense. The report comes from the 7.6.x line, so retest on a current build.

Save a copy first and compare the line total afterward.

When a script or plugin beats the menu commands

A script handles what the menu and regex methods struggle with: files of millions of lines, first-occurrence rules without reversing, and custom comparison logic. The cost is setup the menu commands never ask for.

PythonScript

A script posted by Ekopalypse on the Notepad++ community forum stores each line in a set, records the line numbers of repeats, then deletes them from the bottom up. It removes any duplicate, not only consecutive ones.

A forum test ran removal on a file of 6,000,100 lines and found that generating the file took longer than removing its duplicates.

Without a wrapper, reverting takes one undo step per deleted line, so the author added beginUndoAction and endUndoAction around the call.

There are a couple of gaps too. A script version that stores lines together with their endings misses a last line that has none (Scott Sumner), and one posted version ignores blank lines.

Install the PythonScript plugin first. The forum threads link its home and download pages.

TextFX

YouTube player

TextFX removes duplicates by sorting, so the original order is gone.

On 32-bit builds it works. Tick Sort outputs only UNIQUE (at column) lines under TextFX Tools, select the text, then run a case-sensitive or case-insensitive sort (Stack Overflow answer). Testers confirmed the 32-bit builds sorted.

64-bit builds are another story. A 7.6.6 user found TextFX missing from Plugins Admin, two testers reported an experimental 64-bit build did not sort, and another poster pointed to a 64-bit build on GitHub (Notepad++ community, 2019).

Alan Kilborn suggested moving past TextFX in that thread. The built-in commands cover this job, so skip TextFX unless you already run the 32-bit editor.

Which method fits your file?

Start with Remove Duplicate Lines. Move to another method only when order, key columns or file size rule it out.

Sort-then-consecutive, the route many tutorials lead with, is the weakest default. It scrambles line order and adds a step the whole-document command skips. Keep it for builds whose menu lists only the consecutive command.

MethodKeeps original orderScattered duplicatesMain limit
Remove Duplicate LinesYes, first keptYesExact whole-line match only
Sort, then Remove Consecutive Duplicate LinesNoYes, after the sortSort order replaces the original
Regex, unsorted patternYes, last keptYesComplexity errors on large files
PythonScriptYes, first keptYesPlugin and script setup

When duplicates are defined by a key, not the whole line

Both built-in commands compare entire lines, so two rows that share an ID but differ elsewhere count as different.

For a key at the start of each line, guy038 posted a pattern that keeps the first line of each run sharing the same first characters (Notepad++ community). Put (?-s)^((.{7}).*\R)(?:\2.*\R?)+ in Find what and \1 in Replace with.

The 7 is the key length in his example, so change it to match yours. The matching lines must sit next to each other, which means sorting first when keys are scattered.

When the file is big or the job repeats

Once regex complexity errors appear, switch to the script. It also reruns in one click on the next file, which the Replace dialog can’t do.

Duplicate Line Removal in Notepad++ FAQ

Can I assign a keyboard shortcut to Remove Consecutive Duplicate Lines?

Not through the Shortcut Mapper. A 2019 community thread found the command missing from it, and the workaround was a macro in shortcuts.xml that calls command ID 42077.

One user paired it with the sort command (42059) in a single macro bound to a key. On a standard install the file sits in the user AppData folder (%AppData%\Notepad++).

Can I undo a duplicate line removal?

Yes. Press Ctrl+Z right after the command or the regex Replace All, while the tab is still open.

Save a copy of the original before a large run. Once the file is saved and closed, the undo history is gone.

How do I remove duplicate lines from many files at once?

The Line Operations commands act on the open document only. A Stack Overflow answer ran the unsorted regex through Search > Find in Files with a filter and a directory, then clicked Replace in Files.

Back up the folder first. The regex size limits apply to every file in the run.

Is there a way to mark duplicate lines without deleting them?

Yes. Open the Mark tab, set Search Mode to Regular expression, tick Bookmark line, and use (?-si)^(.+)(?=(.*\R)+\1$) (guy038, Notepad++ community).

It marks every line that has a later identical copy, however many lines sit between them. On long files it returns an Invalid Regular Expression error.

Checking a Duplicate Line Cleanup Before You Save

Compare the status bar line total before and after the run, then save the result under a new file name. The original stays untouched until the numbers make sense.

The order matters, because each step changes what the next one can prove.

  1. Save a copy under a new name.
  2. Trim trailing spaces and unify line endings.
  3. Run the command, then compare line totals.

Trimming rewrites every line that ends in a space, so the saved copy differs from the original in more than the removed lines. Skip the trim only when exact whitespace matters, and accept that space-padded copies will survive.

For a second check, run the Mark tab regex (?-si)^(.+)(?=(.*\R)+\1$) on the result. Zero marked lines means no exact duplicates remain.

An Invalid Regular Expression error means the check didn’t run, which happens on long files. Rely on the line totals there.

This position was verified in November 2026 against forum reports on builds up to 8.7.5. Retest after an upgrade, since selection and line-ending handling have differed between releases.

Bogdan Sandu

Stay sharp. Ship better code.

Every week: one curated article, one tool worth knowing, one tip you can use tomorrow. No noise, no padding.