You had a very similar thread some time ago. Any learnings from that?
However, try
awk ' {LN[$1]; HD[$2]; MX[$1,$2]++}
END { printf "%10s", ""; for (i in HD) printf "%10s", i; print "";
for (j in LN) {printf "%10s",j; for (i in HD) printf "%10s", MX[j,i]+0; print ""}
}
' file
c1 c2 c3 c4
a 1 0 0 0
b 0 1 0 0
c 1 0 0 0
d 0 0 1 0
e 0 0 0 1
you are right. however it was based on 3 columns and here it is just two.
I noticed that if the column names are longer for example instead of c1 c1_abajgdhd_1234x, the script is printing bit wrong because some header names were not separated by tab.
tr -d '\r' <$1 | awk ' {LN[$1]; HD[$2]; MX[$1,$2]++}
END { printf "%10s", ""; for (i in HD) printf "%10s", i; print "";
for (j in LN) {printf "%10s",j; for (i in HD) printf "%10s", MX[j,i]+0; print ""}
}
'