[Top][All Lists]

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

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

From: arnold
Subject: Re: What is done when FS is set in an action?
Date: Tue, 22 Jun 2021 07:58:43 -0600
User-agent: Heirloom mailx 12.5 7/5/10

Peng Yu <pengyu.ut@gmail.com> wrote:

> 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,

You don't understand how standards work. If it doesn't say that
changing FS affects the fields, then doing so does not and can not.

> 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

Incorrect. POSIX is very clear.

In any case, I am NOT going to argue 35 year old design decisions
with you. You're welcome to your opinions, but they carry no weight
with me.

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

There are easy ways to accomplish what you want, within the
scope of the language as it exists. These are documented and
discussed in the manual. But since you write:

> I don't like to read online manuals.

You have doomed yourself to live in darkness and ignorance,

However, as it happens, I understand the sentiment. The gawk
manual is available in pre-formatted PDF format, suitable for

If you have access to a duplexing laster printer (a likely circumstance
in this day and age), then it should take about half a ream of paper
to print. You can put that into a binder and read it at your leisure,
away from the screen.  This has the advantage of giving you a place to
make notes, as well as letting you use a highlighter for important points.

If you prefer a bound book version, order a copy of
for yourself.  The only thing of importance that it doesn't cover is
namespaces, and you can get by without that.

If you restrict your knowledge of gawk to what you can get from the
man page, your programming will never mature, and you will always
be frustrated by what you don't know.


reply via email to

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