On Fri, 26 Jun 2020 21:41:57 +0100, Stuart Henderson wrote:

> The Sep 10, 2019 version of awk introduced a change in handling this:
>
>   ifconfig egress | awk '/inet / {FS="[ .]"; print "host-"$4"-"$5"}'
>
> Given a line like
>
>         inet 10.20.30.40 netmask 0xffffff00 broadcast 10.20.30.255
>
> it used to return host-30-40, now it returns host-0xfffffff0-broadcast.
> The new behaviour is the same as gawk and old behaviour can be obtained
> by doing this instead
>
>   ifconfig egress | awk -F '[ .]' '/inet / {print "host-"$4"-"$5}'
>
> I don't know which is "correct" (the manpage isn't enlightening) but
> it was a bit unexpected so I wanted to at least draw attention to it
> in case it breaks somebody else's script.

The current behavior is correct.  The old behavior was a bug because
field splitting is supported use the value of FS at the time the
record was read.  Setting FS after the line has been read is too
late.

You need to either set FS via the -F flag or inside a BEGIN block.

 - todd

Reply via email to