I do use GNU Emacs for almost every text file related thing. Functions like search, replace, cut, paste, etc are all quickly mastered. But, then I've faced a different situation. I had to replace a string, repeat some numbers and put another string. The answer: regular expressions.
Emacs has a regular expression replace function. To access it, just type: "Ctrl + Alt + Shift + 5" (too much keys huh... ?) And it asks what should be searched. In my case, in which I wanted to capture the regex match, I did type \([0-9][0-9][0-9]\) to locate a 3 digit numbers and capture them. Then I typed enter and did tell Emacs what it should put in those numbers place: ID=\1; mv \1 ./safebox/\1
And enter again and ! to replace all. That is it.