bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] in-place edit request


From: Assaf Gordon
Subject: Re: [bug-gawk] in-place edit request
Date: Tue, 25 Dec 2012 20:54:14 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.7) Gecko/20120922 Icedove/10.0.7

Hi,

On 12/25/12 16:08, Aharon Robbins wrote:

and inplace.awk becomes something like

        @load "setstdout"
        BEGINFILE {
                set_stdout(FILENAME "." PROCINFO["pid"])
        }
        ENDFILE {
                reset_stdout()
                system(sprintf("mv %s %s.bak&&  mv %s.%d %s",
                        FILENAME, FILENAME,
                        FILENAME, PROCINFO["pid"], FILENAME))
        }


I like the idea of "inplace" awk (it would be very useful),
but please note that the suggested solution has some of the issues discussed 
here:
http://www.pixelbeat.org/docs/unix_file_replacement.html
(which was mentioned in the coreutil's discussion about the generic inplace 
utility)

and it would also be a bit problematic if the filename has spaces, or starts 
with a dash.
A simple quote protection would help, but not completely solve the problem, as 
"mv" could be many
things on different systems, and weird extreme cases could lead to 
unpredictable results.

sed's inplace code in "closedown()" and "ck_rename()" has some extra protection 
code that might be beneficial in order to provide a robust in-place editing.

-gordon






reply via email to

[Prev in Thread] Current Thread [Next in Thread]