Community
    • Login

    Add new line of text at end/target line for multiple files?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 2.8k 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.
    • VampireSeraphinV
      VampireSeraphin
      last edited by

      Hello. I would like to use the find and replace function across multiple text files to add a new line to the end of the file, or even better, to a target line (second line in this case).

      This tutorial is very close to what I want to do: https://notepad-plus-plus.org/community/topic/11987/add-line-of-text-to-beginning-of-multiple-files/4 but I’m not sure how to modify it for my needs.

      Does anyone know how I can do this?

      Claudia FrankC 1 Reply Last reply Reply Quote 0
      • Claudia FrankC
        Claudia Frank @VampireSeraphin
        last edited by

        @VampireSeraphin

        give it a try with the following (regex and match newline needs to be checked)

        Find what: ^(.*?\r\n)(.*)$
        Replace: \1SomeText\r\n\2
        

        ^ Start from beginning of file and the ? restricts to find as less as possible chars until a \r\n (windows end of line marks) appears
        which basically means the first line. Having enclosed in () means it get captured in variable \1 .
        Next capture group gets the rest of the text until $ end.

        In replace you need to add the text and the eols \r\n together with the matching groups.

        Cheers
        Claudia

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