Pivoting data based on a header field

Hi Team,

Could you please help me with the below scenario.

I have a file which is in the below format.

Zipcode,001,001f,002,002f,003,003f,004,004f,005,005f,006,006f,007,007f
0050, ,0, ,0, ,0, ,1,*,7, ,7, ,7
0060, ,0, ,0, ,7, ,0,*,7, ,0, ,0

Would need the output as below.
First field will be repeating for the values.
Header value need to be pivoted as second field, and corresponding header values in the third field.

005,001,0
005,001f,	
005,002,0
005,002f,	
005,003,0
005,003f,	
005,004,1
005,004f,*	
005,005,7
005,005f,0
005,006,7
005,006f,	
006,001,0
006,001f,	
006,002,0
006,002f,	
006,003,0
006,003f,	
006,004,0
006,004f,	
006,005,0
006,005f,0
006,006,7
006,006f,

Please provide your valuable inputs.

Hi you can try adapting the following approach to your needs:

$ awk 'NR==1{n=split($0,H); next} {for(i=2;i<=NF;i++) print $1,H,$i}' FS=, OFS=, file
0050,001, 
0050,001f,0
0050,002, 
0050,002f,0
0050,003, 
0050,003f,0
0050,004, 
0050,004f,1
0050,005,*
0050,005f,7
0050,006, 
0050,006f,7
0050,007, 
0050,007f,7
0060,001, 
0060,001f,0
0060,002, 
0060,002f,0
0060,003, 
0060,003f,7
0060,004, 
0060,004f,0
0060,005,*
0060,005f,7
0060,006, 
0060,006f,0
0060,007, 
0060,007f,0
1 Like