[RndTbl] Little script puzzle help.

Adam Thompson athompso at athompso.net
Tue Jul 31 10:59:59 CDT 2012

Err... that does involve the use of temporary files, it's just hidden from 
you.  I'm not aware of any way around that unless the replacement text 
happen to be exactly the same length (in bytes) as the original text, in 
which case you need to use dd(1) with skip= and/or seek= to avoid creating 
a temporary file.  Even sed(1) and/or perl(1) with "-i" will create a 
temporary file behind the scenes, since there's no magic syscall (nor a 
physical way) to _slide_ the bits forwards or backwards on the disk!

If you're going for ultimate portability, I recommend you fall back to 
ed(1), since that can be used either as-is with ed(1) or with patch(1). 
The command-line invocation will be slightly uglier than than with ex(1), 

-Adam Thompson
 athompso at athompso.net
 (204) 291-7950 - direct
 (204) 489-6515 - fax

> -----Original Message-----
> From: roundtable-bounces at muug.mb.ca [mailto:roundtable-
> bounces at muug.mb.ca] On Behalf Of Sean Cody
> Sent: Monday, July 30, 2012 10:38 PM
> To: Continuation of Round Table discussion
> Subject: Re: [RndTbl] Little script puzzle help.
> 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