title: How can I grep content from file1 matching file2 and put them in the order of file2
body: <p>I have <code>file1.txt</code> with content:</p>
  
  <pre><code>rs002
  rs113
  rs209
  rs227
  rs151 
  rs104
  </code></pre>
  
  <p>I have <code>file2.txt</code> with content:</p>
  
  <pre><code>rs113   113
  rs002   002
  rs227   227
  rs209   209
  rs104   104
  rs151   151
  </code></pre>
  
  <p>I want to get the lines of <code>file2.txt</code> that match the records in <code>file1.txt</code>, for which I tried:</p>
  
  <pre><code>grep -Fwf file1.txt file2.txt 
  </code></pre>
  
  <p>with output as follows:</p>
  
  <pre><code>rs113   113
  rs002   002
  rs227   227
  rs209   209
  rs104   104
  rs151   151
  </code></pre>
  
  <p>This extracts all the matching lines, but it is in the order of occurrence in <code>file2.txt</code>. Is there any way to extract the matching records while maintaining the order from <code>file1.txt</code>? The desired output is as follows:</p>
  
  <pre><code>rs002   002
  rs113   113
  rs209   209
  rs227   227
  rs151   151
  rs104   104
  </code></pre>