Transposing rows and columns (pivoting) using shell scripting

Here is the contents of an input file.

A,1,2,3,4 
10,aaa,bbb,ccc,ddd 
11,eee,fff,ggg,hhh 
12,iii,jjj,lll,mmm 
13,nnn,ooo,ppp  

I wanted the output to be

A 
10 1 aaa 
10 2 bbb 
10 3 ccc 
10 4 ddd 
11 1 eee 
11 2 fff 
11 3 ggg 
11 4 hhh  .....

and so on How to do it in ksh shell scripting? Kindly help me out guys...thanks in advance...

And what did you try so far?

to be frank, i dont have any idea on how to proceed :frowning:

Are you a pro or is this home work?

I am interested in learning unix. So I am doing self learning. Not a pro :slight_smile:

Ok, but you can't learn something without putting in any effort...:eek:

Yes, i accept. Atleast guide me on how to start with it.

I should begin with reading scripting tutorials/books and visit these forums.

Consider the follow code:

awk -F, 'NR==1{n=split($0,a,FS);print $1;next}{for(i=2;i<=n;i++)print $1,a,$i}' file

Should an explanation of the code above make any sense to you? Maybe I'm wrong but I doubt it.....

I would be glad if you explain me your code. Please!