Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Help with subst...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 2089 of 2317
Post > Topic >>

Help with substr

by jose.gaspar.ruas@[EMAIL PROTECTED] Dec 3, 2007 at 02:44 AM

Can someone please help me with the following problem with substr.

When I run

awk -f test.awk chess

where test.awk is the script

BEGIN { print "Ol=81=E1!" }

/ActFrom\[1\]/{
             S1L =3D $0;#
             sub(/ActFrom\[1\]=3D"/,"",S1L);
                 sub(/";/,"",S1L);
              p=3DS1L+0;
              }
/Boards\[1\]=3D/{m1=3D$0;
      sub(/Boards\[1\]=3D"/,"",m1);
      P1=3Dsubstr(m1,p,1);
                   }
END{print p;
	print m1;
	print P1;
}

and the chess is a file containing the follwoing lines

Boards[0]=3D"xxxxxxxxxqxxxpkppxxxxxpxPxxxQRxxxrxxxxxxxxxxxPxxxxxxxxPPxxxxxxK=
x
b";
Boards[1]=3D"xxxxxxxxxqxxxpxppxxxxxpkPxxxQRxxxrxxxxxxxxxxxPxxxxxxxxPPxxxxxxK=
x
w";
Boards[2]=3D"xxxxxxxxxqxxxpxppxxxxxpkPxxxQxxRxrxxxxxxxxxxxPxxxxxxxxPPxxxxxxK=
x
b";
Boards[3]=3D"xxxxxxxxxqxxxpxppxxxxxxkPxxxQxxpxrxxxxxxxxxxxPxxxxxxxxPPxxxxxxK=
x
w";
Boards[4]=3D"xxxxxxxxxqxxxpxppxxxxQxkPxxxxxxpxrxxxxxxxxxxxPxxxxxxxxPPxxxxxxK=
x
b";
ActFrom[0]=3D"14";
ActTo[0]=3D"23";

I expected the result

29
xxxxxxxxxqxxxpxppxxxxxpkPxxxQRxxxrxxxxxxxxxxxPxxxxxxxxPPxxxxxxKx w";
Q

since the character "Q" is in the 29th position at the string m1 but I
get

29
xxxxxxxxxqxxxpxppxxxxxpkPxxxQRxxxrxxxxxxxxxxxPxxxxxxxxPPxxxxxxKx w";
x

where the x is the first position in the string m1.

Can someone please point out my mistake?

Th****s in advance.

Gaspar
 




 3 Posts in Topic:
Help with substr
jose.gaspar.ruas@[EMAIL P  2007-12-03 02:44:48 
Re: Help with substr
Janis <janis_papanagno  2007-12-03 05:07:16 
Re: Help with substr
jose.gaspar.ruas@[EMAIL P  2007-12-03 05:20:52 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 15:05:28 CDT 2008.