Community
    • Login

    Wanting to change every other time a word comes up.

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    8 Posts 3 Posters 962 Views 1 Watching
    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 Offline
      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 Offline
        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 Offline
          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 Offline
            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 Offline
              no hanks
              last edited by

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • no hanksN Offline
                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 Offline
                  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 Offline
                    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

                    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                    With your input, this post could be even better 💗

                    Register Login
                    • First post
                      Last post
                    The Community of users of the Notepad++ text editor.
                    Powered by NodeBB | Contributors