Community
    • Login

    Wanting to change every other time a word comes up.

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    8 Posts 3 Posters 435 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.
    • no hanksN
      no hanks
      last edited by

      Looking to make a change every other line of code comes up. this comes up thousands of times in my script and I need to change every other time it comes up.(… represents text that is different in each line and there is a lot of lines between)

      I just want to change every other “space” to space2

      Can this be done?

      From this:
      CODE : …\space.vmdk
      … x 10-20 random lines between
      CODE : …\space.vmdk

      to this
      CODE : …\space.vmdk
      … x10 - 20 random lines between
      CODE : …\space2.vmdk

      CoisesC 1 Reply Last reply Reply Quote 1
      • Alan KilbornA
        Alan Kilborn
        last edited by Alan Kilborn

        Find: (?-is)^\QCODE : ...\space.vmdk\E(?:.*\R){10,20}\K\QCODE : ...\space.vmdk\E
        Replace: CODE : ...\\space2.vmdk
        Search mode: Regular expression

        no hanksN 1 Reply Last reply Reply Quote 3
        • CoisesC
          Coises @no hanks
          last edited by

          @no-hanks

          If every appearance of \space.vmdk “counts” — that is, it doesn’t appear in comments or other contexts that aren’t part of the “every other instance” rule — then this is easy:

          Open Search | Replace… from the menu, and enter:

          Find what : \\space\.vmdk.*?\K\\space\.vmdk
          Replace with : \\space2.vdmk
          Search Mode : Regular expression
          . matches newline : CHECKED

          then click Replace All.

          If context matters, then it gets more complicated. I’m not sure if “CODE : ” in your sample means literally those characters at the start of a line, so I’m not going speculate on what might be needed without more information.

          Note: Because of the \K in the above expression, you must use Replace All; if you try to test with individual find and replace steps, it won’t work. Do it this way:

          Find what : (\\space\.vmdk.*?\\space)\.vmdk
          Replace with : ($1)2.vdmk
          Search Mode : Regular expression
          . matches newline : CHECKED

          if you need or want to do sequential find and replace.

          no hanksN 1 Reply Last reply Reply Quote 3
          • no hanksN
            no hanks @Alan Kilborn
            last edited by no hanks

            @Alan-Kilborn

            Hi, thanks for your reply the actual code doesn’t have the text “… x 10-20 random lines between” I was using that as a example that there is a random number of lines between the text

            also the … are just shortened down text to make it easier to see. sorry for any confusion

            Thanks for your response but unfortunately this didn’t work. I do appreashate the effort though. someone else posted a solution that worked.

            1 Reply Last reply Reply Quote 0
            • no hanksN
              no hanks
              last edited by

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • no hanksN
                no hanks @Coises
                last edited by

                @Coises
                Thanks, this did exactly what I needed!

                Alan KilbornA 1 Reply Last reply Reply Quote 0
                • Alan KilbornA
                  Alan Kilborn @no hanks
                  last edited by Alan Kilborn

                  @no-hanks

                  My solution did work, you just didn’t ask a good question.
                  @Coises just mentally fixed your question’s problems before answering, I guess.
                  We don’t always read minds the same way here; I tend not to try.

                  EDIT: You did say “… represents text that is different in each line and there is a lot of lines between” and I took that into account for the “random” lines, but I truly thought you meant it literally for the “space” lines. So, sorry about that.

                  no hanksN 1 Reply Last reply Reply Quote 2
                  • no hanksN
                    no hanks @Alan Kilborn
                    last edited by

                    @Alan-Kilborn

                    Sorry that one was on me, im still new at using notepad++ and wasn’t sure how to word my question. I do again apricate your effort.

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