Talk About Network



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: parsing a t...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 17 Topic 2217 of 2236
Post > Topic >>

Re: parsing a text file

by Janis Papanagnou <Janis_Papanagnou@[EMAIL PROTECTED] > Apr 8, 2008 at 12:15 AM

[ 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 = -1;}
> 
> function push(x) {  stack[++nStackPtr] = x; }
> 
> function pop() {
>   if (nStackPtr == -1) return  nStackPtr;
> 
>   return stack[nStackPtr--];
>                }
>   {
> 
>        for (nField = 1;nField <= NF;nField++)
>        if (match($nField, "<")) {
>           nPrevious = 0;
>           for (nLoop = nField-0;nLoop > 0 && nPrevious < 3;nLoop--)
>                 if (!match($nLoop, "<")) {
>                   push($nLoop);
>                   nPrevious++;
>                                           }
>           for (nLoop = 0;nLoop < nPrevious;nLoop++)
>             printf("%s ", pop());
>             printf("%s", $nField);
> 
>         nFollowing = 0;
>         for (nLoop = nField+0;nLoop < NF && nFollowing < 3;nLoop++)
>           if (!match($nLoop, "<")) {
>                 printf(" %s",  $nLoop);
>                 nFollowing++;
>                                     }
>           printf("\n");
> 
>  }
> 
> } # 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




 17 Posts in Topic:
parsing a text file
ric <ricardo7@[EMAIL P  2008-04-07 10:01:05 
Re: parsing a text file
gazelle@[EMAIL PROTECTED]  2008-04-07 17:17:26 
Re: parsing a text file
ric <ricardo7@[EMAIL P  2008-04-07 14:29:48 
Re: parsing a text file
Janis Papanagnou <Jani  2008-04-08 00:15:18 
Re: parsing a text file
Janis Papanagnou <Jani  2008-04-08 00:10:01 
Re: parsing a text file
"Anton Treuenfels&qu  2008-04-07 22:31:43 
Re: parsing a text file
Ed Morton <morton@[EMA  2008-04-07 17:14:10 
Re: parsing a text file
ric <ricardo7@[EMAIL P  2008-04-07 15:36:52 
Re: parsing a text file
ric <ricardo7@[EMAIL P  2008-04-07 16:00:54 
Re: parsing a text file
Janis Papanagnou <Jani  2008-04-08 01:05:40 
Re: parsing a text file
ric <ricardo7@[EMAIL P  2008-04-07 19:07:38 
Re: parsing a text file
Ed Morton <morton@[EMA  2008-04-08 07:16:06 
Re: parsing a text file
Janis <janis_papanagno  2008-04-08 05:47:41 
Re: parsing a text file
Ed Morton <morton@[EMA  2008-04-08 07:58:29 
Re: parsing a text file
ric <ricardo7@[EMAIL P  2008-04-08 08:03:47 
Re: parsing a text file
ric <ricardo7@[EMAIL P  2008-04-08 14:39:18 
Re: parsing a text file
Ed Morton <morton@[EMA  2008-04-09 12:38:49 

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 May 16 8:32:45 CDT 2008.