Paste the files contents differently

Hello ,

I want to segregate by file contents in a much simpler format ie input file

Wednesday May 16 11:59:44 IST 2007
90376 44136 process1 pid1
90200 43208 process1 pid2
90200 43208 process1 pid3
90200 43208 process1 pid4
Wednesday May 16 12:00:45 IST 2007
90376 44136 process1 pid1
90200 43208 process1 pid2
90200 43208 process1 pid3
90200 43208 process1 pid4
Wednesday May 16 12:01:46 IST 2007
90376 44136 process1 pid1
90200 43208 process1 pid2
90200 43208 process1 pid3
90200 43208 process1 pid4

desired output
date,pid1(1st),pid1(2nd),pid2(1st),pid2(2nd),pid3(1st),pid3(2nd),pid4(1st),pid4(2nd)
Wednesday May 16 11:59:44 IST 2007,90376,44136,90200,43208,90200,43208,90200,43208
Wednesday May 16 12:00:45 IST 2007,90376,44136,90200,43208,90200,43208,90200,43208
Wednesday May 16 12:01:46 IST 2007,90376,44136,90200,43208,90200,43208,90200,43208

Also the number of pid and date/Time may be variant in number.....

I have tried by using for loop and paste option but no luck ...
Anaybody pls suggest

KRegards,
Aparna

Try that:

awk '
function print_datas() {
   if (datas) print datas;
   datas = "";
}
NF==6 {   # Date/Time
   print_datas();
   datas = $0;
   next;
}
{
   datas = datas "," $1 "," $2;
}
END {
   print_datas();
}
   ' inputfile

Jean-Pierre.