On 10.06.2015 14:21, Kenny McCormack wrote:
> In article <ml95bv$idq$
1...@news.m-online.net>,
> Janis Papanagnou <
janis_pa...@hotmail.com> wrote:
>> On 10.06.2015 08:59, Kenny McCormack wrote:
>>> In article <ml8jjj$e0u$
1...@news.m-online.net>,
>>> Janis Papanagnou <
janis_pa...@hotmail.com> wrote:
>> [...]
>>>>
>>>> My initial surprise stems from the fact that after that processing the map
>>>> file was empty! Then I realized that despite the file 'map' is only *read*
>>>> it will be emptied due to the 'inplace' function.
>>>
>> [...]
>>>
>>> In a way, it would be nice to be able to turn the 'inplace' magic on and
>>> off on a per-file basis. That is, to be able to say "Do the 'inplace'
>>> magic only for my 'main' file." Maybe some global flag, say, in
>>> PROCINFO[].
>>
>> Maybe yet easier if gawk would just respect the read-only flags of the
>> filesystem and not change such files. (Currently gawk silently ignores
>> the read-only flag and overwrites the file.)
>
> You gotta admit that both of the "solutions" you've proposed are klunky and
> weird.
Well, I'm not that sure as you seem to be. Given the actual logic - and you
made a strong statement upthread:
>> This is all working-as-designed. The point is that 'inplace' is some
>> powerful magic, and it fundamentally changes the way AWK works.
that means that I would have to consider re-designing my code, because it
does (against my expectation) not work just at the shell interface level.
The obvious and straightforward way to address that "changed logic" is to
add that 'print'.
The 'chmod' thing was actually just a try (behavioural analysis) that also
didn't work as I expected, and, as I noticed, is (whether sensible or not)
even documented behaviour in the GNU manual:
"[...] redirects standard output to a temporary file configured to have
the same owner and permissions as the original."
> Maybe effective, but, really, you want to "fix" this by changing
> file permissions to read-only?
Not really. Though if it would have worked I might have used it in those
rare cases where I'd have wanted a terse workaround. (OTOH, if it worked
it would probably be a saner behaviour of awk to abort with an error. I'm
yet undecided about the best behaviour here.)
> I mean, if you're gonna do that, you might
> as well just revert to the old way of using the shell to implement the
> "inplace" functionality.
Yes, this might indeed be an option in certain cases. Currently, though,
I have a situation where it doesn't fit well:
awk '...' one_mapfile tons-of-html-files-to-fix.html...
That means to rewrite all prints to print ... > FILENAME".new" and
shell looping over all files. Not very satisfying.
>
> (Or by adding a silly extra 'print' statement into your AWK code so that
> the "mapping" file gets overwritten every single time you run your script?)
(Actually that is the direct consequence of the new 'inplace' semantics.)
An observation that should not be dismissed in the given context is the
actual behaviour of all awks in case of a standard construct like:
cond { print > "file" }
Here the file will *not* be overwritten if the condition never matches
(or respectively the file not created if there was none existing before).
>
> My solution, of basically fixing the 'inplace.awk' include file, is on the
> right track. It only looked verbose the way I presented it because, for
> demonstration purposes, I included the code inline rather than that which
> is the right, long-term, solution - fixing the include file itself, so that
> the problem is fixed forevermore. See my next post/response for more
> detail on this, but note for now that the idea was to implement was I
> suggested in the paragraph above (the one that starts with "In a way...").
Thanks for your engagement! Appreciated.
Janis