Pivoting using shell scripts

Hi ,
Please any one help using shell scripts achieve the below output(pivoting on top_cd i mean type code values will come as individual columns and fixed amount is value for that .Any help would be greate

 tx_id    tx_amt     typ_cd   fixed_dis_amt  
100     200            mc                     0.4
101     300            sc                       0.2

expecting output

 tx_id    tx_amt     mc                     sc 
100     200            0.4                    null
101     300            null                    0.2
awk '
NR==1 {t[tc++]=$1; t[tc++]=$2; next;}
{a[NR,t[0]]=$1; a[NR,t[1]]=$2; if (! pt[$3]) t[tc++]=$3; a[NR,$3]=$4; pt[$3]=$3}
END {
   $0="";
   for (i=0; i<tc; i++) $0=$0 t ((i<tc) ? "\t" : "");
   print $0;
   for (i=2; i<=NR; i++) {
      $0="";
      for (j=0; j<tc; j++) {
         $0=$0 ((a[i,t[j]]) ? a[i,t[j]] : "null") ((j<tc) ? "\t" : "");
      }
      print $0;
   }
}
' input

Try also, esp. with a larger file with several more columns,

awk '
NR==1           {HD = $1 OFS $2
                 HDC = 2
                 next
                }
!($3 in COLS)   {COLS[$3] = ++HDC
                 HD = HD OFS $3
                }
                {T[$1 OFS $2]++
                 VAL[$1 OFS $2 OFS $3] = $4
                }
END             {print HD
                 for (t in T)   {$0 = t
                                 for (c in COLS) $COLS[c] = VAL[t OFS c]?VAL[t OFS c]:"null"
                                 print
                                }
                }
' OFS="\t" file

Input

[akshay@localhost tmp]$ cat f
 tx_id    tx_amt     typ_cd   fixed_dis_amt  
100     200            mc                     0.4
101     300            sc                       0.2

Script

[akshay@localhost tmp]$ cat test.awk
FNR==1{
	h = $1 OFS $2
}
FNR>1{
	A[$1,$2] = $1 OFS $2; B[$3]; C[$1,$2,$3] = $4
}
END{
	for(i in A)
	{
		f = ""
		for(j in B)
		{
			if(h)h = h OFS j
			ins = i SUBSEP j
			c = ins in C ? C[ins] : "null"
			f = f ? f OFS c : A OFS c
		}
		if(h)
		{ 
			print h
			h = "" 
		}
		print f
	}
	
}

How to execute ?

[akshay@localhost tmp]$ awk -vOFS="\t" -f test.awk f

Output

tx_id	tx_amt	mc	sc
101	300	null	0.2
100	200	0.4	null