This question is philosophically similar to a question that’s come up time and time again here:
- Search and replace text in all files of a linux directory
- How to search-replace content within files in Ubuntu Linux?
- Linux search and replace a complex string
But they (with the exception of the last one) all deal with simple replacements. I have a somewhat large block of code which appears in many files (I wish copy/pasting source code was punishable by law), and I need to replace it.
Is there anything that will help me out here? I want to avoid “sed”ifying the block (as is done in the third similar question above) because that will take the better part of a day. If I have to temporarily install some particular text editor, so be it.
The nice thing about your question is that you’re dealing with fixed strings rather than regular expressions…which makes the problem relatively simple. You could write something to do the job for you without too many problems.
The solution I’ve linked to isn’t optimal, but it does work, and it doesn’t rely on matching only opening/closing lines (that is, it only replaces verbatim matches). The basic idea is: