title: How to find pattern and make operation in another field in awk?
body: <p>I have a file with 4 columns separated by space like this bellow:</p>
  
  <pre><code>1_86500000 50 1_87500000 19
  1_87500000 13 1_89500000 42
  1_89500000 25 1_90500000 10
  1_90500000 3 1_91500000 11
  1_91500000 23 1_92500000 29
  1_92500000 34 1_93500000 4
  1_93500000 39 1_94500000 49
  1_94500000 35 1_95500000 26
  2_35500000 1 2_31500000 81
  2_31500000 12 2_4150000 50
  </code></pre>
  
  <p>The First and Third columns are not in phase so I can not divide the value of one by another.
  As there are only two or one possible columns $1 or $3, a solution would be look for the pattern and divide its value in the another column or set it to 0 if there is none like this expected result shows:</p>
  
  <p>P.S. the second field in this expected result is just illustrative to shown the division.</p>
  
  <pre><code>1_86500000 0/50 0
  1_87500000 19/13 1.46154
  1_89500000 42/25 1.68
  1_90500000 10/3 3.333
  1_91500000 11/23 0.47826
  1_92500000 29/34 0.85294
  1_93500000 4/39 0.10256
  1_94500000 49/35 1.4
  2_35500000 0/1 0
  2_31500000 81/12 6.75
  2_4150000 50/0 50
  </code></pre>
  
  <p>I do not archived anything by myself other than this. So I do not have any starting point by now.</p>
  
  <p>I tried separate the fields merged with _ to see if I could match by subtracting the coordinates. If I got 0 would mean that the columns was in phase and correct. But I could not go further.</p>
  
  <pre><code>awk '{if( ($5-$2)==0) print $1,$2,$3,$4,$5,$6}' file
  </code></pre>
  
  <p>I tried to match both columns but I only got phased results:</p>
  
  <pre><code>awk '{if(($1==$3)) print $1,$4/$2}' file
  </code></pre>
  
  <p>Can you help me?</p>