I needed to add a php script on the beginning of 2000 files. So, I find the solution, maybe this will help anyone to do this with regex.
-
2Is this a self answer to a question? If yes then Remove the answer part from the question and post it as an answer. – Mohammad Yusuf Jan 19 '17 at 06:47
-
hello, yes, I post it as an answer – Just Me Jan 20 '17 at 07:18
2 Answers
First, you have to select the first line on text: ^\A(.*)$
Then, search and replace like this:
Search: ^\A(.*)$
Replace By: ANY_TEXT \r$1
I use GrepWin to replace a big text, not just a single line. Remember that \r or \n are use to add a new line. If you don't want to use one of those, you will be able to add anything at the beginning of first line, without space it by another line ANY_TEXT $1
Another way to to this:
Search: \A(?-s){1}(?s)(.*)
Replace By: ANY_TEXT \r$1
And another way:
Search: (?s)(.*)
Replace by: ANYTHING \n\1
Now, if you want to add something at the end of first line:
Search: ^\A(.*)\K$
Replace with: ANY_WORDS
And, finally, if you want to add something after the last line on text:
Search: ^(.*)$\z
Replace by: $1 \nANY_WORDS

- 864
- 2
- 18
- 28
^\A(.*)$
did not work for me in all case since I sometimes had something like an = at the beginning of the text. ^(.*)$
helped to pick up everything.

- 858
- 2
- 8
- 18