• Login
Community
  • Login

Find and select multiple lines to change order

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
18 Posts 6 Posters 880 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.
  • G
    guy038
    last edited by guy038 Sep 17, 2021, 11:32 PM Sep 17, 2021, 11:25 PM

    Hello, @victor-fansler, @terry-r and All,

    Aaarrrgggh ! Always this damn problem of texts that do not end with a last line break !

    So, before running the regexes, just be sure that your current file ends with a final line-break ( View > Show Symbol > Show All Characters )

    I also, realized that my second regex did not take in account such a possibility !


    Indeed, in the last alternative of my second regex, the part ^(.+\R){2}(?=^\R) searches for 2 complete lines, with their line-breaks ( CRLF ) but ONLY IF it is followed with a pure blank line

    So, either :

    • Use my previous second search regex (?-s)^.+(?=\R(?:.+\R)*Account: (.+)\R(.+)\R)|^(.+\R){2}(?=^\R) and your current file must end this way :
    SECOND to last lineCRLF
    LAST NON-empty lineCRLF
    CRLF
    
    • Or use this new search version (?-s)^.+(?=\R(?:.+\R)*Account: (.+)\R(.+)\R)|^(.+\R){2}(?=^\R|\z) and your current file could simply end as below :
    SECOND to last lineCRLF
    LAST NON-empty ineCRLF
    

    BR

    guy038

    A 1 Reply Last reply Sep 18, 2021, 1:55 AM Reply Quote 2
    • A
      Alan Kilborn @guy038
      last edited by Sep 18, 2021, 1:55 AM

      @guy038 said in Find and select multiple lines to change order:

      Always this damn problem of texts that do not end with a last line break !

      I gave up dealing with that problem long ago when I started to use the editorconfig plugin. With it you can specify that files should always end with an line-ending sequence.

      Too bad that isn’t a native feature of Notepad++.

      M 1 Reply Last reply Feb 15, 2022, 2:25 PM Reply Quote 2
      • G
        guy038
        last edited by guy038 Feb 15, 2022, 6:08 PM Feb 15, 2022, 1:52 PM

        Hello @victor-fansler, @terry-r, @alan-kilborn and All,

        You said, in your chat message :

        The “Camera” is a placeholder and can be any text, but will end with a Date and Time

        So I suppose that all these lines always end with the three uppercase letters PST

        If this assumption is right, here are new versions of the regexes ( The first and second one ). Note also that I improved these regexes :

        Now, you don’t even need to separate any section with blank line(s) ;-))


        So starting with your INPUT text, where I added some empty lines :

        Video Return
        Camera-1 02/14/2022 08:31AM PST
        Account: Customer Name - Server Name
        Video Return
        Camera-1 02/14/2022 02:27AM PST
        Account: Customer Name - Server Name
        Connection Lost to Camera
        Camera-1 02/14/2022 12:25AM PST
        Account: Customer Name - Server Name
        
        Video Return
        Camera-1 02/14/2022 12:23AM PST
        Account: Customer Name - Server Name
        Video Return
        Camera-1 02/13/2022 09:31AM PST
        Camera-4 02/13/2022 09:31AM PST
        Camera-2 02/13/2022 09:31AM PST
        Camera-3 02/13/2022 09:31AM PST
        Account: Customer Name - Server Name
        
        
        
        Video Return
        Camera-1 02/13/2022 04:57AM PST
        Camera-4 02/13/2022 04:57AM PST
        Camera-3 02/13/2022 04:57AM PST
        Account: Customer Name - Server Name
        Connection Lost to Camera
        Camera-2 02/13/2022 01:43AM PST
        Account: Customer Name - Server Name
        Video Return
        Camera-1 02/13/2022 01:42AM PST
        Camera-4 02/13/2022 01:42AM PST
        Camera-2 02/13/2022 01:42AM PST
        Camera-3 02/13/2022 01:42AM PST
        Account: Customer Name - Server Name
        
        
        Connection Lost to Camera
        Camera-1 02/12/2022 07:18PM PST
        Camera-4 02/12/2022 07:18PM PST
        Camera-2 02/12/2022 07:18PM PST
        Camera-3 02/12/2022 07:18PM PST
        Account: Customer Name - Server Name
        

        First, use the following regex S/R in order to place the line Video Return OR Connection Lost to Camera, after each line Account :

        SEARCH (?-s)^(.+\R)((?:.+\R)+?Account: .+\R)\R*

        REPLACE \2\1

        We get this text :

        Camera-1 02/14/2022 08:31AM PST
        Account: Customer Name - Server Name
        Video Return
        Camera-1 02/14/2022 02:27AM PST
        Account: Customer Name - Server Name
        Video Return
        Camera-1 02/14/2022 12:25AM PST
        Account: Customer Name - Server Name
        Connection Lost to Camera
        Camera-1 02/14/2022 12:23AM PST
        Account: Customer Name - Server Name
        Video Return
        Camera-1 02/13/2022 09:31AM PST
        Camera-4 02/13/2022 09:31AM PST
        Camera-2 02/13/2022 09:31AM PST
        Camera-3 02/13/2022 09:31AM PST
        Account: Customer Name - Server Name
        Video Return
        Camera-1 02/13/2022 04:57AM PST
        Camera-4 02/13/2022 04:57AM PST
        Camera-3 02/13/2022 04:57AM PST
        Account: Customer Name - Server Name
        Video Return
        Camera-2 02/13/2022 01:43AM PST
        Account: Customer Name - Server Name
        Connection Lost to Camera
        Camera-1 02/13/2022 01:42AM PST
        Camera-4 02/13/2022 01:42AM PST
        Camera-2 02/13/2022 01:42AM PST
        Camera-3 02/13/2022 01:42AM PST
        Account: Customer Name - Server Name
        Video Return
        Camera-1 02/12/2022 07:18PM PST
        Camera-4 02/12/2022 07:18PM PST
        Camera-2 02/12/2022 07:18PM PST
        Camera-3 02/12/2022 07:18PM PST
        Account: Customer Name - Server Name
        Connection Lost to Camera
        

        Now, using this second regex S/R :

        SEARCH (?-is)^.+PST(?=\R(?:.+PST\R)*?(Account: .+)\R(.+)\R)|^(.+\R){2}

        REPLACE ?1\1 - $0 - \2

        We get the OUTPUT text :

        Account: Customer Name - Server Name - Camera-1 02/14/2022 08:31AM PST - Video Return
        Account: Customer Name - Server Name - Camera-1 02/14/2022 02:27AM PST - Video Return
        Account: Customer Name - Server Name - Camera-1 02/14/2022 12:25AM PST - Connection Lost to Camera
        Account: Customer Name - Server Name - Camera-1 02/14/2022 12:23AM PST - Video Return
        Account: Customer Name - Server Name - Camera-1 02/13/2022 09:31AM PST - Video Return
        Account: Customer Name - Server Name - Camera-4 02/13/2022 09:31AM PST - Video Return
        Account: Customer Name - Server Name - Camera-2 02/13/2022 09:31AM PST - Video Return
        Account: Customer Name - Server Name - Camera-3 02/13/2022 09:31AM PST - Video Return
        Account: Customer Name - Server Name - Camera-1 02/13/2022 04:57AM PST - Video Return
        Account: Customer Name - Server Name - Camera-4 02/13/2022 04:57AM PST - Video Return
        Account: Customer Name - Server Name - Camera-3 02/13/2022 04:57AM PST - Video Return
        Account: Customer Name - Server Name - Camera-2 02/13/2022 01:43AM PST - Connection Lost to Camera
        Account: Customer Name - Server Name - Camera-1 02/13/2022 01:42AM PST - Video Return
        Account: Customer Name - Server Name - Camera-4 02/13/2022 01:42AM PST - Video Return
        Account: Customer Name - Server Name - Camera-2 02/13/2022 01:42AM PST - Video Return
        Account: Customer Name - Server Name - Camera-3 02/13/2022 01:42AM PST - Video Return
        Account: Customer Name - Server Name - Camera-1 02/12/2022 07:18PM PST - Connection Lost to Camera
        Account: Customer Name - Server Name - Camera-4 02/12/2022 07:18PM PST - Connection Lost to Camera
        Account: Customer Name - Server Name - Camera-2 02/12/2022 07:18PM PST - Connection Lost to Camera
        Account: Customer Name - Server Name - Camera-3 02/12/2022 07:18PM PST - Connection Lost to Camera
        

        I hope that it is your expected text !?

        See you later !

        Best Regards,

        guy038

        A DarthDataD 2 Replies Last reply Feb 15, 2022, 2:02 PM Reply Quote 1
        • A
          Alan Kilborn @guy038
          last edited by Feb 15, 2022, 2:02 PM

          @guy038

          Is there a special reason for the recent revisit to something asked 5 months ago? Just asking…in case I am missing some sort of newly discovered technique…

          1 Reply Last reply Reply Quote 0
          • G
            guy038
            last edited by guy038 Feb 15, 2022, 2:14 PM Feb 15, 2022, 2:12 PM

            Hi, @alan-kilborn,

            Well, it’s just that we cannot place more than 1,000 characters in a chat message. So I preferred to answer in our forum !

            But, indeed, I was asked to create a new post or to continue with that one !

            I have just re-indicated to @victor-fansler, the title of this article

            BR

            guy038

            A 1 Reply Last reply Feb 15, 2022, 2:18 PM Reply Quote 2
            • A
              Alan Kilborn @guy038
              last edited by Feb 15, 2022, 2:18 PM

              @guy038 said in Find and select multiple lines to change order:

              But, indeed, I was asked to create a new post or to continue with that one !

              Ah, OK, makes sense! I wasn’t sure your previous use of “chat” really meant that or just conversation above in this thread.

              Chat is useful if something really gets specific to an OP’s need and really can’t benefit anyone else. Otherwise it is good to see the conversation in a real post.

              1 Reply Last reply Reply Quote 0
              • M
                Michael Vincent @Alan Kilborn
                last edited by Feb 15, 2022, 2:25 PM

                @alan-kilborn said in Find and select multiple lines to change order:

                I gave up dealing with that problem long ago when I started to use the editorconfig plugin. With it you can specify that files should always end with an line-ending sequence.

                I would have thought you’d have a PythonScript for that! :-)

                Cheers.

                A 2 Replies Last reply Feb 15, 2022, 2:30 PM Reply Quote 3
                • A
                  Alan Kilborn @Michael Vincent
                  last edited by Feb 15, 2022, 2:30 PM

                  @michael-vincent said in Find and select multiple lines to change order:

                  I would have thought you’d have a PythonScript for that

                  It would be an easy script, but I don’t tend to re-invent the wheel unless I’m going to make the wheel better. And editorconfig works just fine in this regard, so…just keep rollin’.

                  1 Reply Last reply Reply Quote 2
                  • A
                    Alan Kilborn @Michael Vincent
                    last edited by Feb 15, 2022, 2:42 PM

                    @michael-vincent said in Find and select multiple lines to change order:

                    …PythonScript for that…

                    Well… I looked into my folder of “retired” scripts and I found that I used to use the SCOTT SCRIPT for doing it before I discovered the editorconfig plugin.

                    1 Reply Last reply Reply Quote 3
                    • DarthDataD
                      DarthData @guy038
                      last edited by Feb 15, 2022, 6:50 PM

                      @guy038 Thanks for this and sorry for any confusion. Unfortunately, the lines will not always end with PST. There are different time zones. Primarily PST and MST, but could be MDT as well.

                      Lycan ThropeL 1 Reply Last reply Feb 15, 2022, 8:52 PM Reply Quote 0
                      • Lycan ThropeL
                        Lycan Thrope @DarthData
                        last edited by Feb 15, 2022, 8:52 PM

                        @darthdata ,

                        You really have to stop moving the goal posts. :) Poor @guy038 must have a real life, even if he does love doing this stuff, I suspect he’d like to fix it once and move on. :)

                        Lee

                        1 Reply Last reply Reply Quote 1
                        • G
                          guy038
                          last edited by Feb 20, 2022, 1:50 AM

                          Hi, @darthdata and All,

                          In this case, change the second regex S/R into this one :

                          SEARCH (?-is)^.+(?:PST|MST|MDT)(?=\R(?:.+(?:PST|MST|MDT)\R)*?(Account: .+)\R(.+))|^(.+\R){2}

                          REPLACE ?1\1 - $0 - \2

                          BR

                          guy038

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