Red Hat Bugzilla – Bug 59990
substr does not work
Last modified: 2007-04-18 12:40:27 EDT
From Bugzilla Helper:
User-Agent: Mozilla/4.76 [en] (X11; U; SunOS 5.6 sun4u)
Description of problem:
The attached awk script does not return the correct output, but mostly
return nothing, which seems to be a failure of the substr() function,
which returns the empty string.
upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
lower = "abcdefghijklmnopqrstuvwxyz";
value = "0123456789";
Z = index(upper, "Z") + 1;
V = index(value, "9") + 1;
str = ""
for (i=1; i <= length($1); i++)
c = substr($1, i, 1);
if (c == "-") a = "-"
else if (c == ".") a = "."
else if (c ~ /[0-9]/) a = substr(value, V-index(value,c), 1)
else if (c ~ /[A-Z]/) a = substr(upper, Z-index(upper,c), 1)
else a = substr(lower, Z-index(lower,c), 1);
str = str a;
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1.Save abovementioned test.awk to a file
$ echo foo-bar | awk -f test.awk
3.Observe, that the output is "-z", correct output would be
Actual Results: $ echo foo-bar | gawk-3.1.0 -f test.awk
Expected Results: on a RedHat 6.2 platform:
$ echo foo-bar | gawk -f test.awk
1. the problem also exists with a gawk compiled from gawk-3.1.0 sources on
2. the problem does not exist with a gawk compiled from gawk-3.1.0
sources on RedHat 7.1.
3. the problem does not exist with the gawk-3.0.6 binary from
This seems to work fine for me on a 7.2 system with the current errata rpms
from ftp.redhat.com applied. Does it make a difference if the glibc update
is applied? What is set in /etc/sysconfig/i18n?
Florian La Roche