 <pre><code>$ awk -v RS= -F'\n' '{n=split($1,a,/ /); sub(/\| */,"",$7); print a[n], $7}' file x.x.x.x var1:var2 y.y.y.y var3:var4 z.z.z.z No valid accounts found </code></pre> <p>or if you want to exclude the 3rd line of output, you might want:</p> <pre><code>$ awk -v RS= -F'\n' '$7~/:/{n=split($1,a,/ /); sub(/\| */,"",$7); print a[n], $7}' file x.x.x.x var1:var2 y.y.y.y var3:var4 </code></pre>