title: How to print the data in an order using awk?
body: <pre><code>ABC has x types:
  x.x  used by xyzzy
  x.y.z used by pqr
  a.b.c.d used by mno   
  PQR has x types:
  x.x  used by xyzzy
  x.y.z used by pqr   
  XYZ has x types:
  x.x  used by xyzzy
  p.q.r used by pqr
  </code></pre>
  
  <p><strong>Criteria to get expected output</strong> - </p>
  
  <ul>
  <li>Read the first column of the line where "<code>has x types</code>" is there and
  put it into a variable then move to next line and fetch first column
  of next line in another variable and continue to next line.</li>
  <li>If this line is just above the line which contain "<code>has x types</code>" then
  print variable first and second variable in pipe seperated format.</li>
  </ul>
  
  <p>Expected output -</p>
  
  <pre><code>ABC | a.b.c.d
  PQR | x.y.z
  XYZ | p.q.r
  </code></pre>
  
  <p>I tried this - </p>
  
  <pre><code>awk '$0 ~ /has/ {p=$1}; q=$1; {print p,q}' k
  ABC has x types:
  ABC ABC
  x.x  used by xyzzy
  ABC x.x
  x.y.z used by pqr
  ABC x.y.z
  a.b.c.d used by mno
  ABC a.b.c.d
  PQR has x types:
  PQR PQR
  x.x  used by xyzzy
  PQR x.x
  x.y.z used by pqr
  PQR x.y.z
  XYZ has x types:
  XYZ XYZ
  x.x  used by xyzzy
  XYZ x.x
  p.q.r used by pqr
  XYZ p.q.r
  </code></pre>