On Apr 7, 4:15=A0pm, Janis Papanagnou <Janis_Papanag...@[EMAIL PROTECTED]
>
wrote:
> [ Please don't top-post.]
>
>
>
>
>
> ric wrote:
> > Hi Kenny,
>
> > Well, I'm a AWK newbie, this is my actual code(some friend try to help
> > me):
>
> > ~ric)cat script2.awk
> > #!/usr/bin/awk -f
>
> > BEGIN { nStackPtr =3D -1;}
>
> > function push(x) { =A0stack[++nStackPtr] =3D x; }
>
> > function pop() {
> > =A0 if (nStackPtr =3D=3D -1) return =A0nStackPtr;
>
> > =A0 return stack[nStackPtr--];
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
> > =A0 {
>
> > =A0 =A0 =A0 =A0for (nField =3D 1;nField <=3D NF;nField++)
> > =A0 =A0 =A0 =A0if (match($nField, "<")) {
> > =A0 =A0 =A0 =A0 =A0 nPrevious =3D 0;
> > =A0 =A0 =A0 =A0 =A0 for (nLoop =3D nField-0;nLoop > 0 && nPrevious <
3;n=
Loop--)
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!match($nLoop, "<")) {
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 push($nLoop);
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 nPrevious++;
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
=A0 =
=A0 =A0 =A0 }
> > =A0 =A0 =A0 =A0 =A0 for (nLoop =3D 0;nLoop < nPrevious;nLoop++)
> > =A0 =A0 =A0 =A0 =A0 =A0 printf("%s ", pop());
> > =A0 =A0 =A0 =A0 =A0 =A0 printf("%s", $nField);
>
> > =A0 =A0 =A0 =A0 nFollowing =3D 0;
> > =A0 =A0 =A0 =A0 for (nLoop =3D nField+0;nLoop < NF && nFollowing <
3;nLo=
op++)
> > =A0 =A0 =A0 =A0 =A0 if (!match($nLoop, "<")) {
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 printf(" %s", =A0$nLoop);
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 nFollowing++;
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
=A0 =
}
> > =A0 =A0 =A0 =A0 =A0 printf("\n");
>
> > =A0}
>
> > } # main
> > ~ric)
>
> The main difference between your approach and the program I posted
> elsethread seems to be that you have introduced some unnecessary
> stack while my solution builds the result by concatenating strings.
> (There seem to be a couple of bugs in your program as well.)
>
> Janis- Hide quoted text -
>
> - Show quoted text -
hi Janis,
Ops,sorry for top-post :)
Your solution,it's much better than the first one.
>>Your data format makes a solution somewhat ugly (see missing space after
t=
he sentence in " works.This ").
I change the data format, have a space:
#cat file
I went fishing for some sea <bass> .
The <bass> part of the song is very moving .
he proposed an elaborate <program> of public works . This information
was taken from the magazine.
the <program> required several hundred lines of code .
The only problem is: is printing after the "."
"proposed elaborate program public works This"
and should said:
"proposed elaborate program public works"
Thanks very much,really
-ric


|