Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming that</p> <ul> <li>there is no ID with more than 2 alternatives</li> <li>the alternative IDs are in the first columns of the "other" files</li> <li>you only want the "x" to appear in col7 when there is no match, not in col8 if there is only one match</li> <li>you can name one character (<code>DELIM</code>) that is no <code>&lt;TAB&gt;</code> and will <strong>never</strong> appear in any <em>altenative</em> ID</li> <li>all files have <em>exactly</em> <strong>one</strong> header line</li> </ul> <p>the following solution works for me</p> <pre class="lang-sh prettyprint-override"><code>$ cat file1 </code></pre> <pre class="lang-none prettyprint-override"><code>ID col2 col3 col4 col5 col6 a a x 43 5 54 b f 4 44 9 51 c h k 90 0 52 </code></pre> <pre class="lang-sh prettyprint-override"><code>$ cat file2a </code></pre> <pre class="lang-none prettyprint-override"><code>AltID col2 col3 ID A1 some thing a B1 more stuff b </code></pre> <pre class="lang-sh prettyprint-override"><code>$ cat file2b </code></pre> <pre class="lang-none prettyprint-override"><code>AltID col2 col3 ID A2 even more a D1 random stuff d </code></pre> <pre class="lang-sh prettyprint-override"><code>$ cat test.awk </code></pre> <pre class="lang-sh prettyprint-override"><code>BEGIN { FS = "\t" OFS = FS DELIM = ";" MISSING = "x" } FILENAME != "file1" { if (FNR != 1) { alt[$4] = (alt[$4] ? alt[$4] "" DELIM : "") "" $1 } next } FNR == 1 { $7 = "AltID" $8 = "AltID2" print next } { idcount = split(alt[$1], ids, DELIM) $7 = (idcount ? ids[1] : MISSING) } idcount &gt; 1 { $8 = ids[2] } 1 </code></pre> <pre class="lang-sh prettyprint-override"><code>$ awk -f test.awk file2* file1 </code></pre> <pre class="lang-none prettyprint-override"><code>ID col2 col3 col4 col5 col6 AltID AltID2 a a x 43 5 54 A1 A2 b f 4 44 9 51 B1 c h k 90 0 52 x </code></pre> <p>Feel free to ask for adjustements or explanations in comments and I'll update my answer accordingly.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload