bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] ^. as field separator


From: arnold
Subject: Re: [bug-gawk] ^. as field separator
Date: Tue, 16 Apr 2019 12:01:54 -0600
User-agent: Heirloom mailx 12.5 7/5/10

Hi.

Thanks for submitting a bug report.

O??uz <address@hidden> wrote:

> I just came across this behavior in gawk 4.2.1 which I can't find an
> explanation for in the POSIX standard, nor in the gawk manual:
>
> $ echo 'foo' | awk 'BEGIN{FS="^.";OFS="|"} {$1=$1} 1'
> ||o
>
> I expected the output to be `|oo` since `^.` should match the first char on
> the line, `f`. I can get that output just be referencing NF before or after
> the assignment:
>
> $ echo 'foo' | awk 'BEGIN{FS="^.";OFS="|"} {NF;$1=$1} 1'
> |oo
>
> $ echo 'foo' | awk 'BEGIN{FS="^.";OFS="|"} {$1=$1;NF} 1'
> |oo
>
> Is this a bug or is that behavior described somewhere in the documentation?

I think I'm going to call this a bug. Here is what I get comparing
different versions:

$ for i in nawk mawk gawk mksawk 'busybox awk' goawk
> do echo ==== $i
> echo 'foo' | $i 'BEGIN{FS="^.";OFS="|"} {$1=$1} 1'
> done
==== nawk
|oo
==== mawk
|||
==== gawk
||o
==== mksawk
|oo
==== busybox awk
|||
==== goawk
|oo

All of nawk (Brian Kernighan's awk), the MKS awk, and goawk agree with your
expectation.  mawk and busybox awk treat the ^ as applying at the start
of each field, and I think that's pretty wrong.

You've touched on a subtle area in the language and in the implementation.
I will see if I can fix this without breaking anything else.

Thanks!

Arnold



reply via email to

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