Add line of text to beginning of multiple files

  • I have 52 files that I need to add a line of text to each one at the very beginning of the file every 2 or 3 days. I want to load this entire folder into Notepadd ++ and do a find and replace in all documents. I have figured out that I can add this line of text before each LINE by using find=^ and replace=lineoftext\r. However, I do not need the line of text after each line in the files. I only need to add this one line of text to the beginning (top) of each file. Does anyone know how I can accomplish this? Thanks in advance for your help with Notepad ++.

  • @Kevin-Hemken

    sorry, don’t understand your question.
    At the end - do you want to have files which only
    have one line content?
    Meaning you wanna empty the file first and then add a line? And this for each file in question?


  • I do not want to delete any data. I simply want to add a line of text to the beginning of each file.

    If the text file is…

    blah blah blah
    blah blah blah

    I want it to be …

    add line of text here
    blah blah blah
    blah blah blah

  • @Kevin-Hemken

    I see
    in find repalce dialog you need to tick regular expression AND . matches newline

    find what:(.*)
    replace with:WHATEVERTEXT\r\n\1

    (.*) find everything (if the dot matches newline has been ticked)

    \r\n is the normal eol for windows
    \1 represents what has been matched by (.*)


  • Thanks. Works perfect!

  • Hello Kevin, Claudia and All,

    An other possibility would be :

    SEARCH (?s).*


    NOTES :

    • The (?s) modifier forces the regex engine to consider that the meta character dot . matches, absolutely, any single character, whatever the . matches new line option is set or unset

    • The $0 form , in replacement, stands for the entire searched regex, that is to say, the actual contents of each scanned file

    REMARK :

    • Due to a N++ regex engine bug, about backward assertions, we cannot use, for instance, the \A assertion, which, normally, represents the very beginning of a file. IF it would have been possible, the S/R would have been, simply :

    SEARCH : \A


    Therefore, the Claudia’s work-around, is a nice solution to that bug !!

    Best Regards,


  • Hi @guy038,

    nice one ( or two :-)) but where did you find the ?s ?
    I can’t seem to see it in the official docs.


  • Search: ^\A(.*)$
    Replace by: ANYTHING \r$1


    Search: ((?s:.*))
    Replace by: ANYTHING \n\1

  • @Claudia-Frank Thanks a lot!
    This saved me a lot of time as I had around 500 files to be modified.

Log in to reply