bug-gawk
[Top][All Lists]
Advanced

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

Re: What is done when FS is set in an action?


From: Peng Yu
Subject: Re: What is done when FS is set in an action?
Date: Mon, 21 Jun 2021 17:30:43 -0500

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html

"Before the first reference to a field in the record is evaluated, the
record shall be split into fields, according to the rules in Regular
Expressions, using the value of FS that was current at the time the
record was read."

The POSIX doc says the above. But it does not say that $1, $2 can not
be changed accordingly, if FS is changed in an action,

Therefore, strictly speaking, the POSIX manual does not specify what
the output (1 or 2) should be for the following command.

awk '{ FS = ":" ; print $1 }' <<< a:b:c

1. a:b:c
2. a

But I think lazy processing (2) makes more sense. That is, don't
assign $1, $2, .. unless one of them is used. This may improve the
performance.

Since NF can modify the array of $1, $2, why not let FS also modify
the array of $1, $2, .. (lazily)?

On Mon, Jun 21, 2021 at 2:06 PM Peng Yu <pengyu.ut@gmail.com> wrote:
>
> Can the manpage contain the whole manual? Many GNU programs have man
> page the same as the manual. I don't like to read online manuals. I
> prefer manpages.
>
> On Mon, Jun 21, 2021 at 9:41 AM Davide Brini <dave_br@gmx.com> wrote:
> >
> > On Mon, 21 Jun 2021 09:34:01 -0500, Peng Yu <pengyu.ut@gmail.com> wrote:
> >
> > > Hi,
> > >
> > > It seems that FS has to be set outside an action. Otherwise, the
> > > result is not very meaningful.
> >
> > You should REALLY REALLY REALLY REALLY read the GNU awk documentation, as
> > suggested countless times already.
> >
> > https://www.gnu.org/software/gawk/manual/gawk.html#Full-Line-Fields
> >
> > --
> > D.
> >
>
>
> --
> Regards,
> Peng



-- 
Regards,
Peng



reply via email to

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