• Login
Community
  • Login

Wanting to change every other time a word comes up.

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
8 Posts 3 Posters 448 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.
  • N
    no hanks
    last edited by Dec 8, 2023, 5:08 PM

    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

    C 1 Reply Last reply Dec 8, 2023, 6:24 PM Reply Quote 1
    • A
      Alan Kilborn
      last edited by Alan Kilborn Dec 8, 2023, 5:46 PM Dec 8, 2023, 5:45 PM

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

      N 1 Reply Last reply Dec 8, 2023, 6:26 PM Reply Quote 3
      • C
        Coises @no hanks
        last edited by Dec 8, 2023, 6:24 PM

        @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.

        N 1 Reply Last reply Dec 8, 2023, 6:34 PM Reply Quote 3
        • N
          no hanks @Alan Kilborn
          last edited by no hanks Dec 8, 2023, 6:33 PM Dec 8, 2023, 6:26 PM

          @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
          • N
            no hanks
            last edited by Dec 8, 2023, 6:28 PM

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • N
              no hanks @Coises
              last edited by Dec 8, 2023, 6:34 PM

              @Coises
              Thanks, this did exactly what I needed!

              A 1 Reply Last reply Dec 8, 2023, 7:52 PM Reply Quote 0
              • A
                Alan Kilborn @no hanks
                last edited by Alan Kilborn Dec 8, 2023, 9:27 PM Dec 8, 2023, 7:52 PM

                @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.

                N 1 Reply Last reply Dec 8, 2023, 8:05 PM Reply Quote 2
                • N
                  no hanks @Alan Kilborn
                  last edited by Dec 8, 2023, 8:05 PM

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