• Login
Community
  • Login

How to keep only unique line

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
11 Posts 3 Posters 4.4k 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 Mar 20, 2018, 1:14 PM

    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

    C 1 Reply Last reply Mar 20, 2018, 1:41 PM Reply Quote 1
    • C
      Claudia Frank @محمد أشرف
      last edited by Mar 20, 2018, 1:41 PM

      @محمد-أشرف

      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 Mar 20, 2018, 1:45 PM Reply Quote 0
      • م
        محمد أشرف @Claudia Frank
        last edited by Mar 20, 2018, 1:45 PM

        @Claudia-Frank

        how can use it ?

        C 1 Reply Last reply Mar 20, 2018, 1:48 PM Reply Quote 1
        • C
          Claudia Frank @محمد أشرف
          last edited by Mar 20, 2018, 1:48 PM

          @محمد-أشرف

          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 Mar 20, 2018, 2:16 PM

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

            C 1 Reply Last reply Mar 20, 2018, 2:20 PM Reply Quote 0
            • C
              Claudia Frank @محمد أشرف
              last edited by Mar 20, 2018, 2:20 PM

              @محمد-أشرف

              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 Mar 20, 2018, 2:40 PM

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

                C 1 Reply Last reply Mar 20, 2018, 3:08 PM Reply Quote 0
                • C
                  Claudia Frank @محمد أشرف
                  last edited by Mar 20, 2018, 3:08 PM

                  @محمد-أشرف

                  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
                  • G
                    guy038
                    last edited by guy038 Mar 14, 2021, 4:51 PM Mar 20, 2018, 7:42 PM

                    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

                    C 1 Reply Last reply Mar 20, 2018, 7:47 PM Reply Quote 2
                    • C
                      Claudia Frank @guy038
                      last edited by Mar 20, 2018, 7:47 PM

                      @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
                      • G
                        guy038
                        last edited by guy038 Mar 20, 2018, 8:56 PM Mar 20, 2018, 8:32 PM

                        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
                        10 out of 11
                        • First post
                          10/11
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors