text: user6271: Is it possible to merge two files together using awk? I have two files with matched  Chrom and pos  column
  file1 has the columns
  CHROM   POS ID  REF ALT QUAL    FILTER  INFO
  
  file2 has the columns 
  CHROM POS ID REF ALT FATHER MOTHER DAUGHTER1 DAUGHTER2 DAUGHTER3 SON1 SON2
  
  I want the final merged file to have these columns
  CHROM   POS ID  REF ALT QUAL    FILTER  INFO FATHER MOTHER DAUGHTER1 DAUGHTER2 DAUGHTER3 SON1 SON2
  
  
  user6271: I did something like  below,
  awk 'FNR==NR{a[$1$2]=$8 FS $12;next}{ print $0, a[$1 $2]}' file1.vcf file2.vcf > Final.vcf
  
  But then the output looks like
  CHROM   POS ID  REF ALT QUAL    FILTER  FATHER MOTHER DAUGHTER1 DAUGHTER2 DAUGHTER3 SON1 SON2 INFO
  
  is it possible to arrange the output to look like 
  CHROM   POS ID  REF ALT QUAL    FILTER  INFO FATHER MOTHER DAUGHTER1 DAUGHTER2 DAUGHTER3 SON1 SON2
  
  
  user3384: It's not awk: but this is a fairly simple python/pandas script (assuming tab-delimited).
  file1
  CHROM   POS ID  REF ALT QUAL    FILTER  INFO
  
  file2
  CHROM POS ID REF ALT FATHER MOTHER DAUGHTER1 DAUGHTER2 DAUGHTER3 SON1 SON2
  
  #!/usr/bin/python
  import pandas as pd
  
  file1 = pd.read_csv('file1.txt', sep='\t')
  file2 = pd.read_csv('file2.txt', sep='\t')
  
  # you can compare file1.shape vs. file2.shape to ensure they match
  # you can also use fileN.sort_values(by=['POS', 'CHROM'], axis=1) to ensure sort matches
  
  file3 = pd.concat([file1, file2[['FATHER', 'MOTHER', 'DAUGHTER1', 'DAUGHTER2', 'DAUGHTER3', 'SON1', 'SON2']]], axis=1)
  
  file3.to_csv('merged_file.txt', sep='\t', index=False)
  
  
  user6290: If you just need to merge column together, you can use paste command:
  paste file1 <(cut -d\  -f6- file2)
  
  In this case the whole file1 is taken and only part of file2 starting from column 6.
  Assuming your data are sorted, another alternative is to use join:
  join -o '1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 2.6 2.7 2.8 2.9 2.10 2.11 2.12' file1 file2
  
  The -o option allows to select column from either file1 or file2.
  
  user650: I'd recommend using R and either merge or one of the joins. Assuming your data is not too large, data.frame + read.delim should suffice to hold the two datasets. If not, try data.table + fread..
  
original_text: 6271: <p>Is it possible to merge two files together using awk? I have two files with matched  Chrom and pos  column</p>
  
  <p>file1 has the columns</p>
  
  <pre><code>CHROM   POS ID  REF ALT QUAL    FILTER  INFO
  </code></pre>
  
  <p>file2 has the columns </p>
  
  <pre><code>CHROM POS ID REF ALT FATHER MOTHER DAUGHTER1 DAUGHTER2 DAUGHTER3 SON1 SON2
  </code></pre>
  
  <p>I want the final merged file to have these columns</p>
  
  <pre><code>CHROM   POS ID  REF ALT QUAL    FILTER  INFO FATHER MOTHER DAUGHTER1 DAUGHTER2 DAUGHTER3 SON1 SON2
  </code></pre>
   6271: <p>I did something like  below,</p>
  
  <pre><code>awk 'FNR==NR{a[<span class="math-container">$1$</span>2]=<span class="math-container">$8 FS $</span>12;next}{ print <span class="math-container">$0, a[$</span>1 $2]}' file1.vcf file2.vcf &gt; Final.vcf
  </code></pre>
  
  <p>But then the output looks like</p>
  
  <pre><code>CHROM   POS ID  REF ALT QUAL    FILTER  FATHER MOTHER DAUGHTER1 DAUGHTER2 DAUGHTER3 SON1 SON2 INFO
  </code></pre>
  
  <p>is it possible to arrange the output to look like </p>
  
  <pre><code>CHROM   POS ID  REF ALT QUAL    FILTER  INFO FATHER MOTHER DAUGHTER1 DAUGHTER2 DAUGHTER3 SON1 SON2
  </code></pre>
   3384: <p>It's not awk: but this is a fairly simple python/pandas script (assuming tab-delimited).</p>
  
  <p>file1</p>
  
  <pre><code>CHROM   POS ID  REF ALT QUAL    FILTER  INFO
  </code></pre>
  
  <p>file2</p>
  
  <pre><code>CHROM POS ID REF ALT FATHER MOTHER DAUGHTER1 DAUGHTER2 DAUGHTER3 SON1 SON2
  </code></pre>
  
  <pre class="lang-py prettyprint-override"><code>#!/usr/bin/python
  import pandas as pd
  
  file1 = pd.read_csv('file1.txt', sep='\t')
  file2 = pd.read_csv('file2.txt', sep='\t')
  
  # you can compare file1.shape vs. file2.shape to ensure they match
  # you can also use fileN.sort_values(by=['POS', 'CHROM'], axis=1) to ensure sort matches
  
  file3 = pd.concat([file1, file2[['FATHER', 'MOTHER', 'DAUGHTER1', 'DAUGHTER2', 'DAUGHTER3', 'SON1', 'SON2']]], axis=1)
  
  file3.to_csv('merged_file.txt', sep='\t', index=False)
  </code></pre>
   6290: <p>If you just need to merge column together, you can use <code>paste</code> command:</p>
  
  <pre><code>paste file1 &lt;(cut -d\  -f6- file2)
  </code></pre>
  
  <p>In this case the whole <code>file1</code> is taken and only part of <code>file2</code> starting from column 6.</p>
  
  <p>Assuming your data are sorted, another alternative is to use <code>join</code>:</p>
  
  <pre><code>join -o '1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 2.6 2.7 2.8 2.9 2.10 2.11 2.12' file1 file2
  </code></pre>
  
  <p>The <code>-o</code> option allows to select column from either <code>file1</code> or <code>file2</code>.</p>
   650: <p>I'd recommend using R and either <code>merge</code> or one of the <code>join</code>s. Assuming your data is not too large, <code>data.frame</code> + <code>read.delim</code> should suffice to hold the two datasets. If not, try <code>data.table</code> + <code>fread</code>..</p>
  