[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] in-place edit request
From: |
Andrew J. Schorr |
Subject: |
Re: [bug-gawk] in-place edit request |
Date: |
Tue, 1 Jan 2013 18:33:43 -0500 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Mon, Dec 31, 2012 at 10:18:32PM +0200, Aharon Robbins wrote:
> Now someone in the community, who thinks this feature is worthwhile,
> needs to step up to the plate and do the work.
I just whipped up a proof of concept. It is attached. It seems to work
on linux. For example, these commands do the right thing:
bash$ gawk -i inplace '{sub(/foo/, "bar"); print}' /tmp/tfile
bash$ gawk -i inplace -v "INPLACE_SUFFIX=.bak" '{sub(/foo/, "bar"); print}'
/tmp/tfile
It has the following known problems:
1. It uses a single static state structure, so it is not reentrant: it will
fail if BEGINFILE is called again without an intervening call to ENDFILE.
I imagine that using the fork extension could trigger a problem with this.
I'm not sure if there are any other problem scenarios.
2. It should probably register an awk_atexit handler to remove the temporary
file if gawk exits before calling ENDFILE.
3. I don't know how portable it is. It uses the following library calls:
stat
mkstemp
fchown
fchmod
close
dup
dup2
unlink
link
rename
Thoughts?
Also, I'm not interested in writing a good wrapper script for this that
supports an optional backup suffix. Somebody who really cares should
take a crack at that.
Regards,
Andy
inplace.c
Description: Text document
inplace.awk
Description: Text document
- Re: [bug-gawk] in-place edit request,
Andrew J. Schorr <=