bug-gawk
[Top][All Lists]
Advanced

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

[bug-gawk] Strange behavior in gawk


From: Derrik Walker v2.0
Subject: [bug-gawk] Strange behavior in gawk
Date: Fri, 05 Dec 2014 23:36:10 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.1

This is hard to explain, so I'll just use my code to explain ...

I have a test file, we'll call test.txt:

1:2:3
4:5:6
.a.b.c
.e.f.g

I have an awk script, we'll call test.awk:

/:/ {
    FS=":"
    print "NF = " NF " - " $0
}

/\./ {
    FS="."
    print "NF = " NF " - " $0
}

If I run the file with gawk, I get:

# gawk -f test.awk test.txt
NF = 1 - 1:2:3
NF = 3 - 4:5:6
NF = 1 - .a.b.c
NF = 4 - .e.f.g

As you can see, the first entry of each FS is wrong!

If I do the same thing with nawk, I get the expected results:

# nawk -f test.awk test.txt
NF = 3 - 1:2:3
NF = 3 - 4:5:6
NF = 4 - .a.b.c
NF = 4 - .e.f.g

The versions of gawk and nawk I'm running:

# rpm -q gawk
gawk-4.1.0-3.fc20.x86_64
# rpm -q nawk
nawk-20121220-2.fc20.x86_64

I'm assuming this a gawk bug, but I am wondering if anyone else has seen it.

Thanks.

--
-- Derrik

Derrik Walker v2.0, RHCE
address@hidden

"Those UNIX guys, they think weird!" -- John C. Dvorak




reply via email to

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