[ILUG] awk question

Brian Foster blf at utvinternet.ie
Sat Feb 21 10:27:19 GMT 2004


 I haven't following this very closely, but my understanding
 is the gawk(1) script in question is basically:

     /RE₁/ { x = $1;     }
     /RE₂/ { y = $3;     }
           { print x, y; }

 and the “problem‟ is apparent-duplicate lines are printed.

 well, what else do you expect the script to do?
 of course it will print an output line for every input line;
 the 3rd ACTION (the last one, with no PATTERN) matches every
 input, so the last-assigned values-to-print («x» and «y» in
 my example above) are printed as the output.

 the solution?  below, I am assuming nothing is to be printed
 until all of the values-to-print have been set, and then the
 cycle repeats.  this is _not_ robust, yer kiloage will vary!:

     BEGIN      {              state = 0; }
     /RE₁/      { x = $1;      state++;   }
     /RE₂/      { y = $3;      state++;   }
     state == 2 { print x, y;  state = 0; }

 this may not quite what is wanted, but is --- possibly ---
 close to what is intended?

cheers!
	-blf-
--
«How many surrealists does it take to    |  Brian Foster      Montpellier,
 change a lightbulb?  Three.  One calms  |  blf at utvinternet.ie      France
 the warthog, and two fill the bathtub   |    Stop E$$o (ExxonMobile)!
 with brightly-colored machine tools.»   |        http://www.stopesso.com



More information about the ILUG mailing list