mbodas@natukawa.intel.com (Milind Bodas) (03/20/91)
Hello,
When a variable is assigned using substr() function in an awk script,
it seems that it cann't be used in certain numerical/logical operations. For
example in following piece of code, the for loop is executed only 4 times
instead of 38 times -
i1 = index($1,"[");
i2 = index($1,":");
i3 = index($1,"]");
last = substr($1,i1+1,i2-i1-1);
first = substr($1,i2+1,i3-i2-1);
#last = last + 10 - 10
#last = last + 10 - 10
for (i=first;i<= last;i++) {
print $0
}
the corresponding input provided is
fwefeffwfgwf
absffg[37:0]
dwfdwfdfwfwff
However if I insert the commented lines, it works fine. Does anyone know
what's wrong?
Milind Bodas
Intel Corporation
tb@sequent.sequent.com (Tony Booker) (03/26/91)
In article <3135@inews.intel.com> mbodas@natukawa.intel.com (Milind Bodas) writes:
When a variable is assigned using substr() function in an awk script,
it seems that it cann't be used in certain numerical/logical operations. For
example in following piece of code, the for loop is executed only 4 times
instead of 38 times -
My man page for awk does say:
BUGS
There are no explicit conversions between numbers and
strings. To force an expression to be treated as a number
add 0 to it; to force it to be treated as a string concaten-
ate "" to it.
--
The above drivel is mine. Company drivel sounds _MUCH_ more plausible ;^)