Questions

Forum Navigation
Please to create posts and topics.

Notepad++ - Remove duplicate lines without plugins

Is there a way to identify and remove duplicate lines in a text file by using Notepad++ without using any external plugin?

Yes, there is....and it is based on using a simple regex inside the "Search and Replace" feature of Notepad++.

Usually, to remove duplicates we would use the very good TextFX plugin available at https://sourceforge.net/projects/npp-plugins/files/TextFX/ (also available at the end of this reply as a mirror link hosted on Heelpbook.net).

But, if we need to just identify and/or remove duplicate lines from a normal or very large text file we could rely on the following approach.

To begin using this approach we need to open the text file we want to analyze, open the Search feature and click on the tab named Replace.

In the Find what field, put this in:

^(.*?)$\s+?^(?=.*^\1$)

The Replace with field should be empty (if you want to actually remove the duplicates), then select Regular Expression and also .matches newline as you can see in the picture.

Notepad++ - Remove duplicate lines without plugins

Click on Replace All and the duplicates in Notepad++ have been removed without TextFX plugin.

If you want, however, to try and use also the TextFX plugin, you can get it using the below download button (no registration needed): TextFX 0.26.