[RndTbl] Little script puzzle help.

Sean Cody sean at tinfoilhat.ca
Mon Jul 30 22:37:58 CDT 2012


On 2012-07-30, at 7:55 PM, Adam Thompson wrote:

> 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
> 


The 'ZZ' note and distinction above was the exact kick in the right direction I needed!
My original attempt (before I started this thread) with ex barfed out with a suprisingly unhelpful message related to buffer naming without context.  Now I get what I was doing wrong... the commands were somewhat right (ZZ is visual mode only).

The solution (at least on OS X and OpenBSD... will try tomorrow on target OS):
	sudo ex -c '23,56d|23r ~/replacement.txt|wq' $someconfigfile

I didn't know/remember the ed & patch connection... very cool/interesting, thanks!

The elegance of this solution is... 1 process is created, file is modified _in place_ and doesn't involve temporary files.

-- 
Sean





More information about the Roundtable mailing list