 <p>A correct solution FWIW:</p> <pre><code>$ awk 'NR==1{n=split($0,d)} {for (i=1;i&lt;=n;i++) printf "%s%s", (i&gt;NF ? d[i] : $i), (i&lt;n ? OFS : ORS)}' file a 12 17 bac 30 42 a 15 18 bac 30 42 a 18 22 bac 30 42 </code></pre>