Community
    • Login

    Move Line Up

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 3 Posters 157 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.
    • Barry LortB
      Barry Lort
      last edited by

      Hello, my project manager wants me to move the “#DESCRIPTION” line above the “#SERVICE” line. Our master list contains several hundred entries. Can I highlight all “#DESCRIPTION” lines and move them above the “#SERVICE” line?

      Thank you.

      #SERVICE:4:8:1:6:0
      #DESCRIPTION   Angus
      #SERVICE:4:7:0:3:0:
      #DESCRIPTION   Ayrshire 
      #SERVICE:5:8:4:1:0
      #DESCRIPTION   Brown-Swiss
      #SERVICE:3:6:7:1:0
      #DESCRIPTION   Galloway
      #SERVICE:4:9:2:5:0
      #DESCRIPTION   Guernsey
      #SERVICE:6:4:7:8:0
      #DESCRIPTION   Hereford 
      #SERVICE:2:7:4:1:0
      #DESCRIPTION   Holstein
      #SERVICE:6:4:2:9:0
      #DESCRIPTION   Piedmontese 
      #SERVICE:3:6:3:1:0
      #DESCRIPTION   Scottish-Highland
      #SERVICE:4:4:9:3:0
      #DESCRIPTION   Shorthorn
      
      PeterJonesP 1 Reply Last reply Reply Quote 1
      • PeterJonesP
        PeterJones @Barry Lort
        last edited by PeterJones

        @Barry-Lort ,

        FIND = (^#SERVICE.*)(\R)(^#DESCRIPTION.*)(\R?)
        REPLACE = $3$2$1$2
        SEARCH MODE = Regular Expression

        This puts the #SERVICE line in memory slot 1, the newline in memory slot 2, the #DESCRIPTION in memory slot 3, and the second newline in slot 4. (But because files sometimes don’t end in a newline, I made it optional with the ?

        The replacement uses slot 3, then 2, then 1, then 2 again, to swap the order of 1 and 3, and to make sure there’s always a newline, whether it was the last line of the file or not.

        ----

        Useful References

        • Notepad++ Online User Manual: Searching/Regex
        • FAQ: Where to find other regular expressions (regex) documentation
        Barry LortB 1 Reply Last reply Reply Quote 2
        • Barry LortB
          Barry Lort @PeterJones
          last edited by

          @PeterJones

          Yes that works very well. Thank you so much. So the $ is a “backreference” in replacement strings when using regular expressions in the Find and Replace dialog?

          Barry

          Barry LortB 1 Reply Last reply Reply Quote 0
          • Barry LortB
            Barry Lort @Barry Lort
            last edited by

            Ok I see the “Useful References” link under Regex Special Characters for Searches, that explains it pretty well.

            Thanks again.

            Barry

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

              Hello, @barry-lort, @peterjones and All,

              @barry-lort, here is an other method to solve your problem !

              Let’s suppose that your file contains 100 lines, so 50 lines beginning with #SERVICE and 50 lines beginning with #DESCRIPTION, as below :

              #SERVICE:4:8:1:6:0
              #DESCRIPTION   Angus
              #SERVICE:4:7:0:3:0:
              #DESCRIPTION   Ayrshire 
              #SERVICE:5:8:4:1:0
              #DESCRIPTION   Brown-Swiss
              #SERVICE:3:6:7:1:0
              #DESCRIPTION   Galloway
              #SERVICE:4:9:2:5:0
              #DESCRIPTION   Guernsey
              #SERVICE:6:4:7:8:0
              #DESCRIPTION   Hereford 
              #SERVICE:2:7:4:1:0
              #DESCRIPTION   Holstein
              #SERVICE:6:4:2:9:0
              #DESCRIPTION   Piedmontese 
              #SERVICE:3:6:3:1:0
              #DESCRIPTION   Scottish-Highland
              #SERVICE:4:4:9:3:0
              #DESCRIPTION   Shorthorn
              #SERVICE:4:8:1:6:0
              #DESCRIPTION   Angus
              #SERVICE:4:7:0:3:0:
              #DESCRIPTION   Ayrshire 
              #SERVICE:5:8:4:1:0
              #DESCRIPTION   Brown-Swiss
              #SERVICE:3:6:7:1:0
              #DESCRIPTION   Galloway
              #SERVICE:4:9:2:5:0
              #DESCRIPTION   Guernsey
              #SERVICE:6:4:7:8:0
              #DESCRIPTION   Hereford 
              #SERVICE:2:7:4:1:0
              #DESCRIPTION   Holstein
              #SERVICE:6:4:2:9:0
              #DESCRIPTION   Piedmontese 
              #SERVICE:3:6:3:1:0
              #DESCRIPTION   Scottish-Highland
              #SERVICE:4:4:9:3:0
              #DESCRIPTION   Shorthorn
              #SERVICE:4:8:1:6:0
              #DESCRIPTION   Angus
              #SERVICE:4:7:0:3:0:
              #DESCRIPTION   Ayrshire 
              #SERVICE:5:8:4:1:0
              #DESCRIPTION   Brown-Swiss
              #SERVICE:3:6:7:1:0
              #DESCRIPTION   Galloway
              #SERVICE:4:9:2:5:0
              #DESCRIPTION   Guernsey
              #SERVICE:6:4:7:8:0
              #DESCRIPTION   Hereford 
              #SERVICE:2:7:4:1:0
              #DESCRIPTION   Holstein
              #SERVICE:6:4:2:9:0
              #DESCRIPTION   Piedmontese 
              #SERVICE:3:6:3:1:0
              #DESCRIPTION   Scottish-Highland
              #SERVICE:4:4:9:3:0
              #DESCRIPTION   Shorthorn
              #SERVICE:4:8:1:6:0
              #DESCRIPTION   Angus
              #SERVICE:4:7:0:3:0:
              #DESCRIPTION   Ayrshire 
              #SERVICE:5:8:4:1:0
              #DESCRIPTION   Brown-Swiss
              #SERVICE:3:6:7:1:0
              #DESCRIPTION   Galloway
              #SERVICE:4:9:2:5:0
              #DESCRIPTION   Guernsey
              #SERVICE:6:4:7:8:0
              #DESCRIPTION   Hereford 
              #SERVICE:2:7:4:1:0
              #DESCRIPTION   Holstein
              #SERVICE:6:4:2:9:0
              #DESCRIPTION   Piedmontese 
              #SERVICE:3:6:3:1:0
              #DESCRIPTION   Scottish-Highland
              #SERVICE:4:4:9:3:0
              #DESCRIPTION   Shorthorn
              #SERVICE:4:8:1:6:0
              #DESCRIPTION   Angus
              #SERVICE:4:7:0:3:0:
              #DESCRIPTION   Ayrshire 
              #SERVICE:5:8:4:1:0
              #DESCRIPTION   Brown-Swiss
              #SERVICE:3:6:7:1:0
              #DESCRIPTION   Galloway
              #SERVICE:4:9:2:5:0
              #DESCRIPTION   Guernsey
              #SERVICE:6:4:7:8:0
              #DESCRIPTION   Hereford 
              #SERVICE:2:7:4:1:0
              #DESCRIPTION   Holstein
              #SERVICE:6:4:2:9:0
              #DESCRIPTION   Piedmontese 
              #SERVICE:3:6:3:1:0
              #DESCRIPTION   Scottish-Highland
              #SERVICE:4:4:9:3:0
              #DESCRIPTION   Shorthorn
              

              Now, just follow this road map :

              • Select any string #SERVICE

              • Run the Edit > Multi-select All > Match Case Only option

              => All strings #SERVICE should have been selected

              • Use the Shift + End shortcut to extend the selection to the end of each line

              • Use the Ctrl + X shortcut to delete these lines and place them in the clipboard

              • Hit two times on the Down arrow key

              => Each cursor/caret should had been moved two lines under

              • Use the Ctrl + V shortcut to recopy all #SERVICE lines to their new location

              • Finally, hit the ESC key to clear the current multi-selection

              Voila !

              Best Regards,

              guy038

              P.S. :

              We could use the multi-selection of all #DESCRIPTION lines, either ! But, in that case, you need to :

              • Add an empty line at the very beginning of your file

              • Hit two times on the Up arrow key, right before the pasting operation

              P.P.S. :

              A similar regex S/R could be :

              FIND (?-s)^(.+\R)(.+(\R)?)

              REPLACE $2(?3:\r\n)$1

              Note that the conditional replacement (?3:\r\n) manages the case where your last #DESCRIPTION line would not end with a line-break !

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