Community
    • Login

    Replace a line with 2 new lines

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 2 Posters 1.1k 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.
    • Edgar RousselinE Offline
      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 Offline
        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 Offline
          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 Offline
            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

            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