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 > Re: Help with s...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 3 Topic 2089 of 2378
Post > Topic >>

Re: Help with substr

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

On 3 dez, 11:07, Janis <janis_papanag...@[EMAIL PROTECTED]
> wrote:
> On 3 Dez., 11:44, jose.gaspar.r...@[EMAIL PROTECTED]
 wrote:
>
>
>
> > 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 =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"xxxxxxxxxqxxxpkppxxxxxpxPxxxQRxxxrxxxxxxxxxxxPxxxxxxxxPPxxx=
xxxKx
> > b";
> >
Boards[1]=3D"xxxxxxxxxqxxxpxppxxxxxpkPxxxQRxxxrxxxxxxxxxxxPxxxxxxxxPPxxx=
xxxKx
> > w";
> >
Boards[2]=3D"xxxxxxxxxqxxxpxppxxxxxpkPxxxQxxRxrxxxxxxxxxxxPxxxxxxxxPPxxx=
xxxKx
> > b";
> >
Boards[3]=3D"xxxxxxxxxqxxxpxppxxxxxxkPxxxQxxpxrxxxxxxxxxxxPxxxxxxxxPPxxx=
xxxKx
> > w";
> >
Boards[4]=3D"xxxxxxxxxqxxxpxppxxxxQxkPxxxxxxpxrxxxxxxxxxxxPxxxxxxxxPPxxx=
xxxKx
> > 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?
>
> Your data seems to not match with your program; there's no "ActTo[1]".
>
> Then you parse the boards first, where p is used, but p is set later,
> when ActTo/From will be parsed.
>
> After you clarified/fixed that I suggest to add some print statements
> in your action blocks for debugging purposes; problems should be more
> apparent then. It's also advisable to reduce your data and program to
> the essential parts before you continue the debugging (or choose to
> post). Helpful is also if you use different characters (not all x'es)
> for the board fields to track any array indexing problems.
>
> Janis
>
>
>
> > Th****s in advance.
>
> > Gaspar

Thank you very much for your answer. I do have a line with
ActFrom[1].It reads
ActFrom[1]=3D"29"; I posted the wrong file but I will try to fix  the
script following your advices.
If I do not succeed I will post again.
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 Tue Oct 14 11:25:49 CDT 2008.