Reading columns, making a new file using another as template

Hi fellas,
I have two files such as:
File 1
interacao,AspAsp,AspCys,CysAsp,CysCys,classe

File 2
interacao,AspAsp,CysAsp,AspCys,CysCys,classe
beta_alfa, DA, CA, DD, CD,ppi

Thus, I want to make a File 3 using the File 1 as model:
e.g.
File 3
interacao,AspAsp,AspCys,CysAsp,CysCys,classe
beta_alfa, DA, DD, CA, CD,ppi

NOTE: I inseted the spaces in the File 2 and File 3 examples just to be easier to see.

In the example I just gave 6 columns, but my real file has 402 columns.
So, to do an awk -F "," '{print $1","$2","$4","$3","$5","$6}'
will not work because I dont know the position of the itens of the File 1 in the File 2 (for example the AspCys could be the sixth, the second, or the last columns).

I hope that you can help me and I would like an small explanation of the code, because I'm newbie and do not know a lot the commands.

Thanks in advance.

Had an almost identical problem a while back, looking for what I wrote.

Meanwhile, you don't have to do "," all the time, you can control that with OFS

$ echo a b c d | awk -v OFS="," '{ $1=$1 } 1'
a,b,c,d

$

This is probably overkill, but I had 500 megabytes of extremely messy flatfiles to merge and sort. This ought to be reliable if not fast, tolerant of things like missing columns.

$ cat col.awk

# Set up input and output separators
BEGIN { FS=","  ;       OFS="," }

# First line in a file?  Figure out what our columns are.
FNR == 1 {
        if(NR==1) # Very first line in very first file
        {
                COLMAX=NF
                # Mark down the contents of all the columns
                for(N=1; N<=NF; N++)
                {
                        ORDER[N]=$N
                        ORDER[$N]=N
                        REORDER[N]=N
                }
                print # Print columns
                next # Go to next line
        }

        # First line in the second/third/fourth file?  Find out how we need to reorder.

        # Delete old columns
        for(X in REORDER)       delete REORDER[X];

        # Match field M against column N.
        for(N=1; N<=COLMAX; N++)
        {
                for(M=1; M<=NF; M++)
                if($M == ORDER[N])
                {
                        REORDER[N]=M;
                        break;
                }

                if(!REORDER[N])
                {
                        print "Couldn't find " ORDER[M] " in " FILENAME >"/dev/stderr";
                        REORDER[N]=NF+10;
                }
        }

        # Only print the first line of columns
        if(NR != 1)     next;
}

# Reorder all input
{
        split($0, ZZT, FS);

        PFIX=""
        STR=""
        for(N=1; N<=COLMAX; N++)
        {
                STR=STR PFIX ZZT[REORDER[N]];
                PFIX=","
        }

        $0=STR
}

1 # Print all other lines

$ awk -f col.awk columnfile data

interacao,AspAsp,AspCys,CysAsp,CysCys,classe
beta_alfa,DA,DD,CA,CD,ppi

$