title: Merge two files based on a mapping in a third file
body: <p>I need to merge two files based on a mapping that is contained in another file. So in the example below, join file1 with file2 where column 2 in file1 matches column 2 in file3 AND column 2 in file2 matches column 4 in file3.</p>
  
  <p>Preferably a solution that utilises unix programs such as awk etc.</p>
  
  <p>file1:</p>
  
  <pre><code>Scf_3L  12798910    T   0   41  0   0   NA  NA
  Scf_3L  12798911    C   0   0   43  0   NA  NA
  Scf_3L  12798912    A   42  0   0   0   NA  NA
  Scf_3L  12798913    G   0   0   0   44  NA  NA
  Scf_3L  12798914    T   0   42  0   0   NA  NA
  Scf_3L  12798915    G   0   0   0   44  NA  NA
  Scf_3L  12798916    T   0   42  0   0   NA  NA
  Scf_3L  12798917    A   41  0   0   0   NA  NA
  Scf_3L  12798918    G   0   0   0   43  NA  NA
  Scf_3L  12798919    T   0   43  0   0   NA  NA
  Scf_3L  12798920    T   0   41  0   0   NA  NA
  </code></pre>
  
  <p>file2:</p>
  
  <pre><code>3L  12559896    T   0   31  0   0   NA  NA
  3L  12559897    C   0   0   33  0   NA  NA
  3L  12559898    A   34  0   0   0   NA  NA
  3L  12559899    G   0   0   0   33  NA  NA
  3L  12559900    T   0   34  0   0   NA  NA
  3L  12559901    G   0   0   0   33  NA  NA
  3L  12559902    T   0   33  0   0   NA  NA
  3L  12559903    A   33  0   0   0   NA  NA
  3L  12559904    G   0   0   0   33  NA  NA
  3L  12559905    T   0   34  0   0   NA  NA
  3L  12559906    T   0   33  0   0   NA  NA
  </code></pre>
  
  <p>file3:</p>
  
  <pre><code>3L  12798910    T   12559896    T
  3L  12798911    C   12559897    C
  3L  12798912    A   12559898    A
  3L  12798913    G   12559899    G
  3L  12798914    T   12559900    T
  3L  12798915    G   12559901    G
  3L  12798916    T   12559902    T
  3L  12798917    A   12559903    A
  3L  12798918    G   12559904    G
  3L  12798919    T   12559905    T
  3L  12798920    T   12559906    T
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>Scf_3L  12798910    T   0   41  0   0   NA  NA    3L    12559896    T   0   31  0   0   NA  NA
  Scf_3L  12798911    C   0   0   43  0   NA  NA    3L    12559897    C   0   0   33  0   NA  NA
  Scf_3L  12798912    A   42  0   0   0   NA  NA    3L    12559898    A   34  0   0   0   NA  NA
  Scf_3L  12798913    G   0   0   0   44  NA  NA    3L    12559899    G   0   0   0   33  NA  NA
  Scf_3L  12798914    T   0   42  0   0   NA  NA    3L    12559900    T   0   34  0   0   NA  NA
  Scf_3L  12798915    G   0   0   0   44  NA  NA    3L    12559901    G   0   0   0   33  NA  NA
  Scf_3L  12798916    T   0   42  0   0   NA  NA    3L    12559902    T   0   33  0   0   NA  NA
  Scf_3L  12798917    A   41  0   0   0   NA  NA    3L    12559903    A   33  0   0   0   NA  NA
  Scf_3L  12798918    G   0   0   0   43  NA  NA    3L    12559904    G   0   0   0   33  NA  NA
  Scf_3L  12798919    T   0   43  0   0   NA  NA    3L    12559905    T   0   34  0   0   NA  NA
  Scf_3L  12798920    T   0   41  0   0   NA  NA    3L    12559906    T   0   33  0   0   NA  NA
  </code></pre>