Replace columns of one file into another

Hi,

I have two files that are different in size (column #'s differ). Each file has the exact same 3 starting columns. File 1 has 240 columns while File 2 has 45 columns.

So if the first 3 columns are the same, I want to replace columns 83 to 163 from File 1 with columns 18 to 33 from File 2.

The file is tab separated and contains equal number of rows.

Thanks

I don't follow this explanation....

163-83=80
33-18=15

So you to replace 80 columns in file1 with 15 columns from file2?
Hmm...... I must be missing the obvious....

Yes replace the 80 with the 15

So in the end the file will have 175 columns (plus the 3 starting columns so 178).

Hope I'm clear

Thanks

Kyle

Hi,
Try this untested one,

nawk 'BEGIN{FS="\t";OFS="\t";line=0;}{match=0;t=0;line++;while(getline inp  <"file2"){t++;if(t==line){split("\t",a,inp);if(a[1]~/^\$1$/ && a[2] ~/^\$2$/ && a[3] ~/^\$3$/){match=1;}}}if(match == 1){for(i=1;i<=NF;i++){if(i==163){print $83;}else{print $i;}}
#traverse a array to change file2#
}}' input_file1

hmm can't seem to get it to work

Check now and update the issue.

hmm numerous errors but it could be my problem

:S

Let's take a set of the simplified sample files to ease debugging/understanding.
kyl1.txt

1 2 3 4 5 6
1 2 3 4 5 6

kyl2.txt:

7 8 9 10
7 8 9 10

Task: substitute columns 2 through 5 in file kyl1.txt with columns 2 through 3 from file kyl2.txt.
I think this sufficiently mimics your original objective. Correct?
nawk -f kyl.awk f1s=2 f1e=5 f2s=2 f2e=3 kyl2.txt kyl1.txt
kyl.awk:

FNR==NR {
   for(i=f2s;i<=f2e;i++)
      f2[FNR]=(f2[FNR])?f2[FNR] OFS $i:$i
   next
}
{
  $f1s=f2[FNR]

  for(i=f1s+1;i<=f1e;i++){
     $i=""
  }
  sub(OFS OFS , OFS)
  $1=$1
  print
}

output:

1 8 9 6
1 8 9 6

Is that what you're after?
If so, substitute the 'f1s=2 f1e=5 f2s=2 f2e=3' with the start/end column values for respective files.