[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-gawk] gawk4 split() function bug? or feature?
From: |
Kent |
Subject: |
[bug-gawk] gawk4 split() function bug? or feature? |
Date: |
Tue, 19 Mar 2013 23:54:44 +0100 |
Hi there,
recently I found something strange about the split() function of gawk,
I am not sure if it is a bug, it would be good if you guys could
explain a bit. Thanks in advance.
my gawk version
kent$ gawk --version
GNU Awk 4.0.2
I know that the 3rd parameter of split() function is a regex. but take
a look these examples:
kent$ echo "foo.bar.baz" | awk '{split($0,a,"."); print "length of
a:" length(a);for (x in a) print a[x]}'
length of a:3
foo
bar
baz
split() looks "." as literature "dot", same as /[.]/ or /\./
but if I do:
kent$ echo "foo.bar.baz" | awk '{split($0,a,/./); print "length of
a:" length(a);for (x in a) print a[x]}'
length of a:12
(here we have 12 emplty lines)
then it worked as regex.
I thought that split() works only with regex constant , not dynamic
regex. however if I try this:
kent$ echo "foo.bar.baz" | awk '{split($0,a,"a."); print "length of
a:" length(a);for (x in a) print a[x]}'
length of a:3
foo.b
.b
(empty line here)
it DID work with dynamic regex and regex constant:
kent$ echo "foo.bar.baz" | awk '{split($0,a,/a./); print "length of
a:" length(a);for (x in a) print a[x]}'
length of a:3
foo.b
.b
(1 empty line)
I read the gawk manual, man page, info page also googled on inet,
cannot find the answer for split(str,array,".") question. Is it a bug?
can you explain me why this happened if it was not a bug?
Thank you!
Best Regards,
Kent
- [bug-gawk] gawk4 split() function bug? or feature?,
Kent <=