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

倖福魔咒の 提交于 2019-12-19 11:34:07

问题


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:


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


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



来源:https://stackoverflow.com/questions/27353876/adding-text-to-the-beginning-of-multiple-files-in-notepad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!