matrix
1 2 3
4 5 6
1 8 9
awk '{for (i=1;i<=NF+1-NR;i++) printf "%s%s",$i,FS; print""}' matrix
1 2 3
4 5
7
awk '{for (i=1;i<=NF;i++) if (NR>=1 && NR==i) {for (j=1;j<=i-1;j++) printf " ";print $(i-0)}}' matrix
1
2
3
4
NF , store the number of field in a record. From your matrix each line have 3 element, so NF is 3.
NR gives you the total number of records being processed or line number, it is a dynamic variable value change from 1-3 reference to your matrix.
You should have a look and research on awk command. http://www.thegeekstuff.com/2010/01/8-powerful-awk-built-in-variables-fs-ofs-rs-ors-nr-nf-filename-fnr/?ref=binfind.com/web