appending several columns with awk and paste

Hello,

I am trying to solve for a couple of hours now the following problem:

I have n files and would like to add the third column of each file to a new file:

temp1.txt

1 2 3
1 2 3
1 2 3

temp2.txt

1 2 4
1 2 4
1 2 4
1 2 4

temp3.txt

1 2 5
1 2 5
1 2 5

and so on....

The desired output would be:

3 4 5 ..
3 4 5 ..
3 4 5 ..

I thought I managed to get the two columns of each file into a new file with awk and with paste -d, but I havent found a away to combine the two.

Any hints would be greatly appreciated!

Thanks!
J

nawk -f cream.awk temp*.txt

cream.awk:

FNR==1{col++}
{
  arr[col,FNR]=$NF
  fnr=(fnr<FNR)?FNR:fnr
}
END {
  for(i=1;i<=col;i++)
     for(j=1;j<=fnr;j++)
        printf("%s%c", arr[j,i], (j==fnr)?ORS:OFS)
}

wonderful, thanks a lot. It works great, eventhough I cant follow it in every detail yet, but thanks again!