AWK:String <--> Integer ??

Milind Bodas mbodas at natukawa.intel.com
Wed Mar 20 13:12:18 AEST 1991


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



More information about the Comp.unix.shell mailing list