How to keep only unique line
-
i have this data
111
111
222
333
444
444
555
555how to keep only unique lines as this result
222
333Thanks much for any help
-
just in case you use python script plugin,
the script like this would do the joblines = editor.getText().splitlines() editor.setText('\r\n'.join([x for x in lines if lines.count(x) == 1]))
Cheers
Claudia -
how can use it ?
-
you need to have python script plugin installed, which, unfortunately, is
currently only available as 32bit version.
If this is the case with your setup, then just use Plugins->PythonScript->New script,
give it a meaningful name and copy the script into it, save it.
Select your document and goto Plugins->Python Script->Scripts and click on your script.Done.
Cheers
Claudia -
I’m sorry but I do not have experience in that
https://prnt.sc/itt5fc -
so clean.py is the script with my code, correct?
If so, open your file which needs to be “cleaned” and then
click on clean under Plugins->Python Script->ScriptsOr did I miss something?
Cheers
Claudia -
When I do this I open it in a new page
https://prnt.sc/ittbcp
When you press Yes
https://prnt.sc/ittbuy -
step by step (assuming python script plugin is already installed)
Goto Plugins->Python Script->New script
give it the name clean2.py and save it
copy the code in the newly created document
and save it
open the document with the data to “clean”
and goto Plugins->Python Script->Scripts and click on clean2
Results in something like
Cheers
Claudia -
Hello, @محمد-أشرف, and All
Sorry, @claudia-frank, I hope you’re not going to have a heart attack, but a simple regex can get it, straightaway ;-))
@محمد أشرف, as your text already contains a sorted list of lines, you can easily get the job done, with a simple regex S/R ! So :
-
Open the replace dialog (
Ctrl + H
) -
Type in the regex
(?-s)^(.+\R)\1+
, in the Find what: zone -
Leave the Replace with: zone
EMPTY
-
Tick the
Wrap around
option -
Select the
Regular expression
search mode -
Finally, click on the
Replace All
button
Et voilà !
Of course, this simple method works ONLY IF the lines are previously sorted :-)
In this other post, below, you asked me about my Facebook account coordinates
https://notepad-plus-plus.org/community/topic/15431/regex-find-duplicate-tags-words-from-some-tags/5
I cannot, as I do not have, presently, any Facebook, Twitter or other social network account :-(( And I suppose I never will !
However, if you don’t mind, you can send me an e-mail, for a specific problem, at :
Best Regards
guy038
-
-
no heart attack yet - still listening into me :-D
But, I give you a second chance as it looks like it doesn’t work correctly with the
provided sample dataCheers
Claudia -
Hi, @محمد-أشرف, @claudia-frank and All
Ah, yes ! I forgot to tell that the last item of the list ( so the last
555
line , in your example) must be followed by a line-break !Everything should be OK !
Cheers
guy038