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


|