Community
    • Login

    How to replace two separate lines.

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    7 Posts 3 Posters 114 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.
    • Brent FickerB
      Brent Ficker
      last edited by

      Trying to Find and Replace two separate lines in a code. I don’t know how to get notepad to recognize this.

      G1 Z10
      G0 Z92
      to
      G1 Z10
      G0 Z38.

      Could anyone help me with this? Thanks

      Victorel PetrovichV 1 Reply Last reply Reply Quote 0
      • Victorel PetrovichV
        Victorel Petrovich @Brent Ficker
        last edited by

        @Brent-Ficker
        Have you tried just copy-paste the respective blocks to go into “find what” and “replace with” boxes of the Find and Replace dialog?

        PeterJonesP Brent FickerB 2 Replies Last reply Reply Quote 0
        • PeterJonesP PeterJones moved this topic from Notepad++ & Plugin Development on
        • Brent FickerB
          Brent Ficker @Victorel Petrovich
          last edited by

          @Victorel-Petrovich
          Yes, l tried that and it ignored the second line and only showed the G1 Z10.

          1 Reply Last reply Reply Quote 1
          • PeterJonesP
            PeterJones @Victorel Petrovich
            last edited by

            @Victorel-Petrovich said in How to replace two separate lines.:

            Have you tried just copy-paste …

            Have you? Because that doesn’t work for me. I just tried, both in an older (v8.4.6 portable) and in a newer copy (8.8.4 installed) and in the newest (v8.8,5 portable), and none did what you claim. I cannot recall it ever working where pasting multi-line works like that (or at least, it hasn’t for a long time)

            Instead, if I copy from G1 to Z92 in that two-line file, and paste it into the FIND or REPLACE fields, it just lists the G1 Z10, without including the second line, and if I do the search, it really only matches a single line, not both lines.

            If I highlight G1 to Z92, then do Ctrl+H to bring up replacement, it populates with what looks like the two lines smooshed together (but the CRLF newline is really invisible there):
            94a9cbe5-d43c-4423-a34f-e267045e874e-image.png

            So @Brent-Ficker could follow the idea behind that:

            1. Highlight the replacement version (G1 to Z38)
            2. Ctrl+H to populate the FIND WHAT in the Replace dialog with the smooshed version
            3. click the 1a716695-9527-4a7e-94d2-6d676b2d21e0-image.png to move it to the REPLACE WITH
            4. highlight the search version (G1 to Z92) and Ctrl+H again, to bring it into the FIND WHAT:
              78139779-1dd3-41f4-af53-7bd5c7cb59a7-image.png
            5. Now Replace or Replace All will do the two-line replacement…

            … But I wouldn’t recommend that, because you cannot actually see what you’re doing, and if you try editing it, you will likely lose that invisible newline in the fields.

            Instead, use Search Mode = Regular Expression, and use the \r\n nomenclature for doing the CRLF line ending. So FIND WHAT = G1 Z10\r\nG0 Z92 and REPLACE WITH = G1 Z10\r\nG0 Z38
            3a688a57-8291-43a3-b16f-edd4df59fb41-image.png

            That allows @Brent-Ficker to customize the search and replacement for any such replacement, even if they don’t have a copy of the replacement text already in the document.

            1 Reply Last reply Reply Quote 1
            • Victorel PetrovichV
              Victorel Petrovich
              last edited by Victorel Petrovich

              @Brent-Ficker @PeterJones
              yes I have tried what I have suggested and worked with no problems. And I’ve been doing such things since I ever learned about find & replace…

              3e214e52-0920-49dd-b3af-301f0ce433c7-image.png

              PeterJonesP 1 Reply Last reply Reply Quote 0
              • PeterJonesP
                PeterJones @Victorel Petrovich
                last edited by PeterJones

                @Victorel-Petrovich said in How to replace two separate lines.:

                yes I have tried what I have suggested and worked with no problems.

                Like I said, copy (Ctrl+C) from the text and paste (Ctrl+V) into FIND WHAT does not do that for me. And it didn’t for @Brent-Ficker, either. What version of Notepad++ are you using?

                And, as i said, even if that did work, it’s not the best method, especially for the replacement, since you don’t always have a copy of the “text I want” to easily grab for copy/paste. Learning how to specify the \r\n in regular expression or extended mode syntax, to get the windows CRLF line endings, is much better for long-term and for crafting replacements that don’t rely on having text you can copy/paste the replacement from.

                1 Reply Last reply Reply Quote 0
                • Victorel PetrovichV
                  Victorel Petrovich
                  last edited by Victorel Petrovich

                  :) you are not lucky, eh?
                  …
                  It looks like the reason it works for me is that I’m using the LF EOL, not CR LF as typical in Windows.

                  Cheers

                  P.S. @Brent-Ficker if you’re not familiar at all with regex, the “Extended” mode setting would work for this particular problem too, to gently introduce you to such things.

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