format file using shell script

Hi All,
I am new to shell scripts. I have a requirement to change the format of a file. Here is the original file:
#student layout
student_name
student_class
student_subject
david
5
chemistry
paul
4
physics
steve
6
mathematics

This is the format i need:
k1,david,5,chemistry
k1,paul,4,physics
k1,steve,6,mathematics

Please suggest ways to do this. I am working on Sun Solaris.
Regards,
Balaji.M

this looks and smells like homework. this is against the rules of unix.com. thread closed!