bug-gawk
[Top][All Lists]
Advanced

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

Re: Conflict between FPAT and empty RS


From: arnold
Subject: Re: Conflict between FPAT and empty RS
Date: Mon, 06 Apr 2020 02:13:23 -0600
User-agent: Heirloom mailx 12.5 7/5/10

Thanks for the report. It seems that settng RS after setting FPAT
also produces correct output.

I will investigate.

Arnold

luciole75w <address@hidden> wrote:

> Hello,
>
> I'm having an odd behavior with GNU awk when using FPAT and RS together. 
> Here is the code.
>
> $ awk '{ print ; $2 = "-" ; print }' RS='' FPAT='\\w+' <<<'a b c d'
> a b c d
> a -
>
> $ ... | xxd -g1 -c8
> 00000000: 61 20 62 20 63 20 64 0a  a b c d.
> 00000008: 61 20 2d 20 20 20 20 0a  a -    .
>
> I'd expect the 2nd print to output "a - c d" but as you can see, 
> modifying the field 2 replaces fields 3 and 4 with spaces in $0. When RS 
> is set to something other than the empty string (or just not set), the 
> output is correct.
>
> Accessing a field is a partial workaround only up to that field, not for 
> fields above. Accessing NF works for all fields. However the workaround 
> must be used *before* $0 is referenced, otherwise the missing fields 
> seem really lost.
>
> $ awk '{ $2 = "-" ; $3 ; print }' RS='' FPAT='\\w+' <<<'a b c d'
> a - c
>
> $ awk '{ $2 = "-" ; NF ; print }' RS='' FPAT='\\w+' <<<'a b c d'
> a - c d
>
> $ awk '{ $2 = "-" ; $0 ; NF ; print }' RS='' FPAT='\\w+' <<<'a b c d'
> a -
>
> Another strange thing which may be related is that setting FS='' before 
> FPAT fixes the behavior.
>
> $ awk '{ $2 = "-" ; print }' RS='' FS='' FPAT='\\w+' <<<'a b c d'
> a - c d
>
> But according to the documentation FPAT should override FS, so I'd 
> actually expect FS to have no effect in this case.
>
> Tested with gawk 4.1.4 and 5.0.1 on Linux Mint 19.3.
>
> Regards,
>
> luciole



reply via email to

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