How to match ID in column in unix?
<p>I am fully aware that similar questions may have been posted, but after searching it seems that the details of our questions are different (or at least I did not manage to find a solution that can be adopted in my case).</p>

<p>I currently have two files: <strong>"messyFile"</strong> and <strong>"wantedID"</strong>. <strong>"messyFile"</strong> is of size <strong>80,000,000 X 2,500</strong>, whereas <strong>"wantedID"</strong> is of size <strong>1 x 462</strong>. On the 253rd line of <strong>"messyFile"</strong>, there are 2500 IDs. However, all I want is the 462 IDs in the file <strong>"wantedID"</strong>. Assuming that the 462 IDs are a subset of the 2500 IDs, how can I process the file <strong>"messyFile"</strong> such that it only contains information about the 462 IDs (ie. of size <strong>80,000,000 X 462</strong>).</p>

<p>Thank you so much for your patience! </p>

<p>ps: Sorry for the confusion. But yeah, the question can be boiled down to something like this. In the 1st row of <strong>"File#1"</strong>, there are 10 IDs. In the 1st row of <strong>"File#2"</strong>, there are 3 IDs (<strong>"File#2"</strong> consists of only 1 line). The 3 IDs are a subset of the 10 IDs. Now, I hope to process <strong>"File#1"</strong> so that it contains only information about the 3 IDs listed in <strong>"File#2"</strong>.</p>

<p>ps2: <strong>"messyFile"</strong> is a vcf file, whereas <strong>"wantedID"</strong> can be a text file (I said "can be" because it is small, so I can make almost any type for it) </p>

<p>ps3: "File#1" should look something like this:</p>

<pre><code>sample#1 sample#2 sample#3 sample#4 sample#5
    0        1       0        0        1
    1        1       2        0        2
</code></pre>

<p>"File#2" should look something like this:</p>

<pre><code>sample#2 sample#4 sample#5
</code></pre>

<p>Desired output should look like this:</p>

<pre><code>sample#2 sample#4 sample#5
   1        0        1
   1        0        2
</code></pre>