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
[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