help need in filtering data

Hello Gurus,

Please help me out of the problem. I ve a input file as below

  input clock;
  input a; //reset all
  input [9:0] b;

  //input comment
  output c;
  output d;
  output [1:0] e;
  input   [4:0] f;
  //output comment

I need the output as follows:

\\Inputs
clock
a
b
f[4:0]
\\Outputs
c
d
e[1:0]

I tried with the following code:

gawk '\
  {
  gsub(/(^ *|^\t)/, "", $0) \\ for cutting one or more space OR tab
  if( match($0,/^input/) ){
          print $0 > "del1"
  }
  if( match($0,/^output/) ){
          print $0 > "del2"
  }
}' file

then merge del1 & del2 perhaps would give the output. then I need to delete the files del1 and del2.

Is there any other simple way ?:confused:

Waitting for your reply

After your gawk command, use basic shell scripting:

gawk ... file && cat del1 del2 >>final_output && rm -f del1 del2

You could use gawk in one pass, however:

gawk '\
  {
  gsub(/(^ *|^\t)/, "", $0) \\ for cutting one or more space OR tab
  }
  /^input/ {
          inputs[++in]=$0;
  }
  /^output/) {
          outputs[++out]=$0;
  }
  END { 
      print "Inputs:"
      for (x=0; x < in; ++x)
         print inputs[x];
      print "Outputs:"
      for (x=0; x < out; ++x)
         print outputs[x];
  }
}' file