Find only the duplicate value
-
Hey. I want to find the duplicate value and to copy those duplicate values.
Eg:
Input:
New York
Dubai
Japan
France
New York
Qatar
JapanOutput:
New York
Japan -
Here’s a possible way to do it:
Invoke Mark dialog (Search (menu) -> Mark…) <–Suggestion: Tie ctrl+m to this action
Find what zone:(?-is)^(.+)(?s)(?=.*?^\1$)
Wrap around checkbox: ticked
Mark line checkbox: ticked
Match whole word only checkbox: unticked
Action: Press the Find All buttonNext invoke Search (menu) -> Bookmark -> Copy Bookmarked Lines
-
@Scott-Sumner said:
Action
Hey,I’m not having the “Mark line” option. Here’s the screenshot. I’m using 7.6 version.
Thanks alot for replying
-
I think I was misquoted!!! :-D
It would be Bookmark line in your case…it really seems that you might have guessed that or even tried it before posting. :-)
-
@Scott-Sumner said:
I think I was misquoted!!! :-D
Yeah, I guessed it :)
But, It’s not working properly? It’s marking the entire document :(
Check out the screenshot -
@Antonsta said:
It’s marking the entire document
Yea, sometimes with a lot of data (I’m looking at your line numbers) the search/mark engine gets overwhelmed and chokes! :(
What if you try sorting your data first?
-
@Scott-Sumner said:
What if you try sorting your data first?
Yes, Sorted it and tried again. Still, it’s marking the entire document :(
Is there any plugins that can do this? :(( -
@Antonsta
Unfortunately, even when the data is sorted, as you found out the regex still caused the same issue. That’s because it’s still trying to search forward over multiple line.When the data is sorted this isn’t necessary anymore as duplicates will appear on consecutive lines.
Thus the regex can be changed to:
(?-is)^(.+)\R\K(\1$)
So this will ONLY look for 2 lines together with the same data. The use of the \K is to forget the first line so the line that gets marked is the duplicate line ONLY.
@guy038 gave a detailed rundown on this issue and ways to circumvent it. Have a look at:
https://notepad-plus-plus.org/community/topic/16489/delete-both-duplicates-regexp-macro/15?page=1Cheers
Terry