[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: Mon, 21 Jun 2021 08:39:21 -0600
User-agent: Heirloom mailx 12.5 7/5/10

This is dicussed thoroughly in the manual (not the man page). See there.

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.
> $ gawk -v FS="x[ ]y[ ]=" -v OFS=, -e '{ NF=NF; print $1,$2 }' <<< 'ax y =b'
> a,b
> $ gawk -v OFS=, -e '{ FS="x[ ]y[ ]="; NF=NF; print $1,$2 }'  <<< 'ax y =b'
> ax,y
> I don't think the man page covers this behavior. It sounds like NF=NF
> uses the old FS instead of the new FS set in the action. This is quite
> counterintuitive. Should this behavior be changed so that only the
> latest set FS is used?
>        As each input record is read, gawk splits the record into
> fields, using the value of the FS  variable
>        as  the field separator.  If FS is a single character, fields
> are separated by that character.  If FS
>        is the null string, then each individual character  becomes  a
> separate  field.   Otherwise,  FS  is
>        expected  to be a full regular expression.  In the special case
> that FS is a single space, fields are
>        separated by runs of spaces and/or tabs and/or newlines.  NOTE:
> The value of IGNORECASE  (see  below)
>        also affects how fields are split when FS is a regular
> expression, and how records are separated when
>        RS is a regular expression.
> -- 
> Regards,
> Peng

reply via email to

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