[RndTbl] Little script puzzle help.

Adam Thompson athompso at athompso.net
Mon Jul 30 19:55:38 CDT 2012


That _is_ an ex(1) script there.  Vi and ex are (usually) the same binary.  Well, except for ZZ - that probably only works in visual mode (wq in command mode is equivalent).
I hope you didn't really mean an ed(1) script, since everything since BSD2 (IIRC) has ex(1).  Although, patch(1) accepts ed(1) scripts... that's the original diff format, in fact (no context at all).
So there's no obstacle to using patch, you just have to go back in time a little bit.
-Adam


Sean Cody <sean at tinfoilhat.ca> wrote:

>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).
>
>
>_______________________________________________
>Roundtable mailing list
>Roundtable at muug.mb.ca
>http://www.muug.mb.ca/mailman/listinfo/roundtable
>



More information about the Roundtable mailing list