title: Awk: how to compare two strings in one line
body: <p>I have a dataset with 20 000 probes, they are in two columns, 21nts each. From this file I need to extract the lines in which last nucleotide in Probe1 column matches last nucleotide in in Probe 2 column. So far I tried AWK (substr) function, but didn't get the expected outcome. Here is one-liner I tried:</p>
  
  <pre><code>awk '{if (substr($2,21,1)==substr($4,21,1)){print $0}}'
  </code></pre>
  
  <p>Another option would be to anchor last character in columns 2 and 4 (<code>awk '$2~/[A-Z]$/</code>), but I can't find a way to match the probes in two columns using regex. All suggestions and comments will be very much appreciated.</p>
  
  <p>Example of dataset:</p>
  
  <pre><code>        Probe 1                     Probe 2
  4736    GGAGGAAGAGGAGGCGGAGGA   A   GGAGGACGAGGAGGAGGAGGA
  4737    GGAGGAAGAGGAGGGAGAGGG   B   GGAGGACGAGGAGGAGGAGGG
  4738    GGAGGATTTGGCCGGAGAGGC   C   GGAGGAGGAGGAGGACGAGGT
  4739    GGAGGAAGAGGAGGGGGAGGT   D   GGAGGACGAGGAGGAGGAGGC
  4740    GGAGGAAGAGGAGGGGGAGGC   E   GGAGGAGGAGGACGAGGAGGC
  </code></pre>
  
  <p>Desired output:</p>
  
  <pre><code>4736    GGAGGAAGAGGAGGCGGAGGA   A   GGAGGACGAGGAGGAGGAGGA
  4737    GGAGGAAGAGGAGGGAGAGGG   B   GGAGGACGAGGAGGAGGAGGG
  4740    GGAGGAAGAGGAGGGGGAGGC   E   GGAGGAGGAGGACGAGGAGGC
  </code></pre>