diff options
Diffstat (limited to 'awklib/eg')
-rw-r--r-- | awklib/eg/lib/inplace.awk | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/awklib/eg/lib/inplace.awk b/awklib/eg/lib/inplace.awk index 6403a228..d1574654 100644 --- a/awklib/eg/lib/inplace.awk +++ b/awklib/eg/lib/inplace.awk @@ -5,10 +5,15 @@ # Please set INPLACE_SUFFIX to make a backup copy. For example, you may # want to set INPLACE_SUFFIX to .bak on the command line or in a BEGIN rule. +# N.B. We call inplace_end() in the BEGINFILE and END rules so that any +# actions in an ENDFILE rule will be redirected as expected. + BEGINFILE { - inplace_begin(FILENAME, INPLACE_SUFFIX) + if (_inplace_filename != "") + inplace_end(_inplace_filename, INPLACE_SUFFIX) + inplace_begin(_inplace_filename = FILENAME, INPLACE_SUFFIX) } -ENDFILE { +END { inplace_end(FILENAME, INPLACE_SUFFIX) } |