Find duplicated strings

Help
Capum130
2011-12-31
2013-01-25
  • Capum130
    Capum130
    2011-12-31

    Hello amigos,  I kindly ask for a script to help me find duplicated strings (and remove the repeated term). I am working with a .txt file which contains emails addresses in notepad++ and there is a bunch of repeated emails. That's it. Respect.

     
  • TextFX sort lines (only unique) will do it easier than a script, assuming you don't mind if the order changes.

    If you need the order to stay the same, then you'd need to add each line to a list, if it wasn't already in the list, then write the list out at the end

    emails = []
    for line in range(0, editor.getLineCount()):
        em = editor.getLine(line).rstrip('\r\n ')
        if em not in emails:
            emails.append(em)
    notepad.new()
    editor.write("\r\n".join(emails))
    
     
  • Capum130
    Capum130
    2011-12-31

    ab12@zmial.com, cd21@zmial.com, ef23@zmial.com, gh32@zmial.com, ij34@zmial.com, mn45@zmial.com, op54@zmial.com, ab12@zmial.com, kl43@zmial.com, kl43@zmial.com,gh32@zmial.com, uv67@zmial.com, mn45@zmial.com, wx76@zmial.com, yz78@zmial.com,

    result something like this ? =

     ab12@zmial.com, cd21@zmial.com, ef23@zmial.com, gh32@zmial.com, ij34@zmial.com, mn45@zmial.com, op54@zmial.com, kl43@zmial.com, uv67@zmial.com, wx76@zmial.com, yz78@zmial.com,
    
     
  • Capum130
    Capum130
    2011-12-31

    dave, i am unfamiliar with TextFX. I can't find where to insert the code.
    is it what you mean:

    emails = [ab12@zmial.com, cd21@zmial.com, ef23@zmial.com, gh32@zmial.com, ij34@zmial.com, mn45@zmial.com, op54@zmial.com, ab12@zmial.com, kl43@zmial.com, kl43@zmial.com, gh32@zmial.com, uv67@zmial.com, mn45@zmial.com, wx76@zmial.com, yz78@zmial.com,] for line in range(0, editor.getLineCount()): em = editor.getLine(line).rstrip('\r\n ') if em not in emails: emails.append(em) notepad.new() editor.write("\r\n".join(emails))
    
     
  • Capum130
    Capum130
    2012-01-03

    davegb3, don't let me unanswered. give me a tutorial or a related topic, anything.
    respect

     
  • My message was obviously unclear - apologies.

    You have 2 options:
    1. TextFX
    2. A script

    TextFX is a plugin (install it with plugin manager).  Select the whole document, and click "sort lines (UNIQUE)" in one of the TextFX menus (sorry I can't remember off hand where it is, but it's under the TextFX menu somewhere.  Advantage of this method is that it has this feature built in, disadvantage is that you will end up with the emails in a different order than you started.  If that's not a problem, then use this method.

    If you need the order to stay the same, then use the script.  The script is a script for the Python Script plugin - as you're on the forum for that plugin I assumed you'd know what to do with it, sorry.  So if you want to use the script method: Plugins, Python Script, New Script, give it a name (say "Make Unique" or something). Copy and paste the code into the file, and save it.   Switch back to your list of emails, Plugins, Python Script, Scripts, Make Unique (or whatever you called your script). Job done.

    Dave.