[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] FPAT $field assignment garbages $0
From: |
arnold |
Subject: |
Re: [bug-gawk] FPAT $field assignment garbages $0 |
Date: |
Mon, 13 Aug 2018 10:06:15 -0600 |
User-agent: |
Heirloom mailx 12.4 7/29/08 |
Hello,
Alex fxmbsw7 Ratchev <address@hidden> wrote:
> echo foo bar | awk -v FPAT=foo '{ $1 = "za"; print }'
> za
>
> GNU Awk 4.2.1, API: 2.0
>
> 'za bar' was expected
You are misunderstanding what FPAT does. It describes the fields, not
what is between them:
$ gawk --version
GNU Awk 4.2.1, API: 2.0 (GNU MPFR 3.1.4, GNU MP 6.1.0)
$ echo foo bar foo | gawk -v FPAT=foo '{ print NF }'
2
$ echo foo bar foo | gawk -v FPAT=foo '{ print $1, $2 }'
foo foo
In the example you give, there is only one field, and your assignment
replaces it.
In short, gawk is working as expected.
Thanks,
Arnold