Community
    • Login

    How to keep only unique line

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    11 Posts 3 Posters 4.3k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • محمد أشرفم
      محمد أشرف
      last edited by

      i have this data

      111
      111
      222
      333
      444
      444
      555
      555

      how to keep only unique lines as this result

      222
      333

      Thanks much for any help

      Claudia FrankC 1 Reply Last reply Reply Quote 1
      • Claudia FrankC
        Claudia Frank @محمد أشرف
        last edited by

        @محمد-أشرف

        just in case you use python script plugin,
        the script like this would do the job

        lines = editor.getText().splitlines()
        editor.setText('\r\n'.join([x for x in lines if lines.count(x) == 1]))
        

        Cheers
        Claudia

        محمد أشرفم 1 Reply Last reply Reply Quote 0
        • محمد أشرفم
          محمد أشرف @Claudia Frank
          last edited by

          @Claudia-Frank

          how can use it ?

          Claudia FrankC 1 Reply Last reply Reply Quote 1
          • Claudia FrankC
            Claudia Frank @محمد أشرف
            last edited by

            @محمد-أشرف

            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

            1 Reply Last reply Reply Quote 0
            • محمد أشرفم
              محمد أشرف
              last edited by

              I’m sorry but I do not have experience in that
              https://prnt.sc/itt5fc

              Claudia FrankC 1 Reply Last reply Reply Quote 0
              • Claudia FrankC
                Claudia Frank @محمد أشرف
                last edited by

                @محمد-أشرف

                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->Scripts

                Or did I miss something?

                Cheers
                Claudia

                1 Reply Last reply Reply Quote 0
                • محمد أشرفم
                  محمد أشرف
                  last edited by

                  When I do this I open it in a new page
                  https://prnt.sc/ittbcp
                  When you press Yes
                  https://prnt.sc/ittbuy

                  Claudia FrankC 1 Reply Last reply Reply Quote 0
                  • Claudia FrankC
                    Claudia Frank @محمد أشرف
                    last edited by

                    @محمد-أشرف

                    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

                    1 Reply Last reply Reply Quote 0
                    • guy038G
                      guy038
                      last edited by guy038

                      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

                      Claudia FrankC 1 Reply Last reply Reply Quote 2
                      • Claudia FrankC
                        Claudia Frank @guy038
                        last edited by

                        @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 data

                        Cheers
                        Claudia

                        1 Reply Last reply Reply Quote 0
                        • guy038G
                          guy038
                          last edited by guy038

                          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

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post
                          The Community of users of the Notepad++ text editor.
                          Powered by NodeBB | Contributors