[TUHS] non-Posix input files

arnold at skeeve.com arnold at skeeve.com
Mon Mar 31 00:00:10 AEST 2025


Doug,

It turns out there wasn't enough context and we both got
confused.  The "requirement" is that

	awk '{ print }' ...

look to the lexer / grammer as if it had been "{ print }\n".

There is no requirement that input "text" files behave as if a
final newline is always there.

Thanks,

Arnold

Douglas McIlroy <douglas.mcilroy at dartmouth.edu> wrote:

> > "The requirement that awk add a trailing <newline> to the program argument
> > text is to simplify the grammar, making it match a text file in form."
>
> This should no more be a *requirement* for awk than globbing should have
> been a requirement for MS-DOS apps. A widespread principle deserves a
> widespread answer. If it is a requirement on awk, then for interoperability
> it should be made a requirement on all programs that handle text files,
> especially editors.
>
> The way to do that, of course, would be to redefine text file to allow a
> non-newline as the last character. Ugh.
>
> Not warning perpetuates travesties like "awk END{print NR}' " giving a different
> answer than "wc -l".
>
> I agree that awk does the kind thing by supplying the final newline. But
> it should recognize that this is non-standard behavior and warn in the
> interest of discouraging the proliferation of garbage.
>
> Postel's so-called "robustness principle" is in play here. "Be conservative
> in what you send, be liberal in what you accept" would better read,
> "Send conservatively; receive amply but grudgingly".
>
> Doug


More information about the TUHS mailing list