19

I have multiple email addresses. I need to find and delete all (including found one). Is this possible in notepad++?

example:epshetsky@test.com, rek4@test.com, rajesh1239@test.com, mohanraj@test.com, sam@test.com, nithin@test.com, midhunvintech@test.com, karthickgm27@test.com, rajesh1239@test.com, mohanraj@test.com, nithin@test.com,

I need results back like

epshetsky@test.com, rek4@test.com, sam@test.com, nithin@test.com, midhunvintech@test.com, karthickgm27@test.com,

How to do in notepad++?

James123
  • 11,184
  • 66
  • 189
  • 343
  • You could find and replace all of them with an empty string, thus deleting them all, and then manually write one line back in. – personjerry Feb 11 '16 at 01:19
  • Possible duplicate of [Removing duplicate rows in Notepad++](http://stackoverflow.com/questions/3958350/removing-duplicate-rows-in-notepad) – AdrianHHH Feb 11 '16 at 09:41
  • @AdrianHHH That duplicate thread is talking about leave it single if find duplicate rows. But My case I need to delete all duplicate rows if find any. – James123 Feb 11 '16 at 17:00
  • OK @James123 wrong duplicate. Have you checked the other questions on Stack Overflow? What did your searches for `[notepad++] delete duplicates` reveal? – AdrianHHH Feb 11 '16 at 17:05
  • https://stackoverflow.com/questions/3958350/removing-duplicate-rows-in-notepad/16293580#16293580 – vr_driver Jul 18 '17 at 11:24

4 Answers4

48

If it is possible to change the sequence of the lines you could do:

  1. sort line with Edit -> Line Operations -> Sort Lines Lexicographically ascending
  2. do a Find / Replace:
    • Find What: ^(.*\r?\n)\1+
    • Replace with: (Nothing, leave empty)
    • Check Regular Expression in the lower left
    • Click Replace All

How it works: The sorting puts the duplicates behind each other. The find matches a line ^(.*\r?\n) and captures the line in \1 then it continues and tries to find \1 one or more times (+) behind the first match. Such a block of duplicates (if it exists) is replaced with nothing.

The \r?\n should deal nicely with Windows and Unix lineendings.

Lars Fischer
  • 9,135
  • 3
  • 26
  • 35
  • Hi, thanks a lot ! It was very useful. However it doesn't work if a duplicate line is on two last lines. – Shark May 16 '18 at 09:36
  • 1
    @Shark Maybe the very last line does not end with a newline? The `\r?\n` means newline, so the newline character is part of the match. (Try pressing Return after the very last line, so that it ends with a newline.) – Lars Fischer May 17 '18 at 17:59
13

You just have to Edit->Line Operations->Remove Duplicate Lines

Sameer Uddin
  • 131
  • 1
  • 2
4

You need the textFX plugin. Then, just follow these instructions:

Paste the text into Notepad++ (CTRL+V). ...
Mark all the text (CTRL+A). ...
Click TextFX → Click TextFX Tools → Click Sort lines case insensitive (at column)
Duplicates and blank lines have been removed and the data has been sorted alphabetically.

Personally, I would use sort -i -u source >dest instead of notepad++

Steve Kolokowsky
  • 423
  • 2
  • 12
0

You could use

Click TextFX → Click TextFX Tools → Click Sort lines case insensitive (at column) Duplicates and blank lines have been removed and the data has been sorted alphabetically.

as indicated above. However, the way I did it because I need to replace the duplicates by blank lines and not just remove the lines, once sorted alphabetically:

REPLACE:
((^.*$)(\n))(?=\k<1>)

by

$3

This will convert:

Shorts
Shorts
Shorts
Shorts
Shorts
Shorts Two Pack
Shorts Two Pack
Signature Braces
Signature Braces
Signature Cotton Trousers
Signature Cotton Trousers
Signature Cotton Trousers
Signature Cotton Trousers
Signature Cotton Trousers
Signature Cotton Trousers
Signature Cotton Trousers
Signature Cotton Trousers
Signature Cotton Trousers
Signature Cotton Trousers
Signature Cotton Trousers

to:

Shorts

Shorts Two Pack

Signature Braces










Signature Cotton Trousers

That's how I did it because I specifically needed those lines.

daviddgz
  • 25
  • 1
  • 8
  • I have the same need, but I can't get your code to work. I pasted your example with the shorts and trousers into Notepad++ but the regex you present above didn't find any matches. And yes, I've got "Regular expressions" selected in the Replace-dialogue window. – Andreas Jansson Oct 08 '21 at 08:57