I have a file in which I need to replace a chunk of lines in on a bunch of hosts.
My initial reaction was to use patch but that won't suffice because the chunk of lines will be different on each host (possibly) so the source part of the patch may not aline to the diff.
Then I was doing to do sed but I can't get the 'r' command do work as I need it to.
So I wrote down a series of vi commands to do what I need to do now I just need to convert that into a sed/ex script...
sudo vi $someconfigfile
23,56d
23
r ~/replacement.txt
ZZ
So what I'm doing here is just dumping lines 23 through 56 in some file and inserting a replacement chunk of text (my not necessarily be 56-23 lines long).
The question here is... is this possible to do with sed and if so how (my brain wont' make the right connections right now, must need a break/food or something).
Even better how would this be done with ex (as I can do a bunch of manual vi commands, how would one automate a repeatable vi session...)?
I could just run a series of search&replace lines corresponding to each section in the replacement text doc but that's violating the spirit of the problem (ie. replace a chunk of text at an arbitrary point in a file with a different chunk of text located in a different file).
Some rules... solution shouldn't be perl/python/whatever because that won't necessarily be found on the UNIX hosts I'm using or may use in the future. Solution shouldn't use GNU extensions of sed/awk due to those being incompatible with non-GNU systems (ie. sysv,bsd,hp etc.).
Any hits, takers?
--
Sean
P.S. I'm doing this as a bit of a personal change management to replay some changes in the distant future (I'm typically using diff/patch for this though this case is a bit a-typical).