1
I have two files of the same length, and I want to swap out one files 3 columns with another file's contents. I want to print the following:
f1Col1 f1Col2 f1Col3 f1Col4 f1Col5 f1Col6 f2Col1 f2Col2 f2Col3 f1Col10 f1Col11 f1Col12
where f1Col1
is the first column of file1
, etc.
I tried to use the following:
awk 'NR==FNR {h1[$1] = $1; h2[$2] = $2; h3[$3] = $3; next} {print $1,$2,$3,$4,$5,$6,h1[$1],h2[$2],h3[$3],$10,$11,$12}' file2 file1
which prints all the necessary columns from file1
but prints blanks instead of the columns from file2
. What's wrong here?
(note: I'm using OS X Yosemite)
Do you want to use only awk, or are other commands allowed as well? – Vincent – 2015-04-20T02:09:53.473
I was curious why it didn't work. – sodiumnitrate – 2015-04-20T21:42:57.177