• Login
Community
  • Login

Replace a line with 2 new lines

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 2 Posters 364 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.
  • E
    Edgar Rousselin
    last edited by Nov 16, 2022, 6:30 PM

    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.

    A 1 Reply Last reply Nov 16, 2022, 6:34 PM Reply Quote 0
    • A
      Alan Kilborn @Edgar Rousselin
      last edited by Alan Kilborn Nov 16, 2022, 6:36 PM Nov 16, 2022, 6:34 PM

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

      E 1 Reply Last reply Nov 16, 2022, 7:14 PM Reply Quote 1
      • E
        Edgar Rousselin @Alan Kilborn
        last edited by Nov 16, 2022, 7:14 PM

        @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

        A 1 Reply Last reply Nov 16, 2022, 7:18 PM Reply Quote 1
        • A
          Alan Kilborn @Edgar Rousselin
          last edited by Nov 16, 2022, 7:18 PM

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