Adding text to the beginning of multiple files in Notepad++

前端 未结 1 527
抹茶落季
抹茶落季 2021-01-15 19:52

I have many text files, and I need to add some text (e.g. MNP) to the beginning of the first line in each file.

How can I do this in Notepad++?

相关标签:
1条回答
  • 2021-01-15 20:35

    (I'm using v6.6.9)

    Make sure to backup your work beforehand, and set proper extension of files to affect and folder to search through before you do this.

    You can use regular expressions. Several places around the internet claim that the regex \A works, but it wasn't working for me, it was cycling byte by byte through. I found that \A^ sticks to 0 position of the file.

    Oddly, I additionally found that I couldn't replace \A or \A^ and have it take effect. This is what worked for me.

    Find: \A^(.*?)
    Replace MNP\1
    

    Truthfully, the \1 in Replace isn't even necessary since I'm cheating and basically telling notepad to look for 0 characters.

    This should work just as well.

    Find: \A^.*?
    Replace MNP
    

    Please backup your work beforehand though.

    Regex Window of Notepad++


    Alternatively, this also seems to work.

    Find: .{0}(.*)
    Replace: MNP\1
    

    It effectively looks for 0 characters followed by the whole document/line (depending on whether . matches newline is checked, this choice won't matter for the outcome however).

    0 讨论(0)
提交回复
热议问题