Community
    • Login

    Replace a line with 2 new lines

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 2 Posters 356 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.
    • Edgar RousselinE
      Edgar Rousselin
      last edited by

      Hello, here is my example:

      I have this code

      …
      N111 M101
      N112 G138 G40 G0X86.462Y606.806 M57
      N113 G90
      N114 ;(Laser Start)
      N115 M50
      N116 M9
      N117 M113
      N118 M50
      …
      I would like to replace the full line of M9 with:
      /N138 M9 M37
      LAT/OutFlowBurn

      What I did was find M9
      Replace with: /N138 M9 M37\nLAT OutFlowBurn

      but this leaves the characters before M9 ie N116 in the line. I wanted to replace everything in that line.

      It looks like this
      N111 M101
      N112 G138 G40 G0X86.462Y606.806 M57
      N113 G90
      N114 ;(Laser Start)
      N115 M50
      N116 /N138 M9 M37
      LAT OutFlowBurn
      N117 M113
      N118 M50
      But I want the N116 gone.
      to look like this

      N111 M101
      N112 G138 G40 G0X86.462Y606.806 M57
      N113 G90
      N114 ;(Laser Start)
      N115 M50
      /N138 M9 M37
      LAT OutFlowBurn
      N117 M113
      N118 M50

      I know is simple but so far I cant figure it out.

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Edgar Rousselin
        last edited by Alan Kilborn

        @Edgar-Rousselin said in Replace a line with 2 new lines:

        Replace with: /N138 M9 M37\nLAT OutFlowBurn
        but this leaves the characters before M9 ie N116 in the line. I wanted to replace everything in that line.

        As an added bonus, you probably also corrupted your file.
        Unless your line-ending type was Unix, then you’re OK.
        For Windows files, you’d want to use \r\n rather than \n in your replace expression.

        Try:

        Find: (?-s)^.*M9.*
        Replace: /N138 M9 M37\r\nLAT OutFlowBurn
        Search mode: Regular expression

        Again, for a Windows file; but if you truly have a Unix file type, leave \n without \r in the replace.

        Edgar RousselinE 1 Reply Last reply Reply Quote 1
        • Edgar RousselinE
          Edgar Rousselin @Alan Kilborn
          last edited by

          @Alan-Kilborn Thank you!
          Will I be able to isolate M9 only in the search. There are instances that I have M95 and it will check it too.

          To be more specific. this line will always be:

          N### M9

          Will it possible to narrow that down?

          Thank you again

          Alan KilbornA 1 Reply Last reply Reply Quote 1
          • Alan KilbornA
            Alan Kilborn @Edgar Rousselin
            last edited by

            @Edgar-Rousselin

            Try:

            Find: ^N\d{3} M9$

            You can learn some of this (regular expression) stuff yourself.
            See the USER MANUAL section.
            Also see the FAQ entry.

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