title: Can these awk actions be combined/optimised, or done differently?
body: <p>I have three bits of awk strung together which seems to do what I need, but could it be done more efficiently/completely differently?</p>
  <p>Currently, the three stages are:</p>
  <ol>
  <li>Quick &amp; dirty check whether field 2 contains an IP or FQDN</li>
  <li>Reverse the last (up to) three elements of the FQDN</li>
  <li>Aggregate the number of occurrences of the field pairing</li>
  </ol>
  <pre><code>awk '$2~/[a-z,A-Z,0-9]\.[a-z,A-Z]+$/{print$2,$1,$3}' ???.20201001.txt|awk '{n=split($1,a,&quot;.&quot;);for(i=0;i&lt;3&amp;&amp;i&lt;n;i++)printf &quot;.%s&quot;,a[n-i];print&quot;&quot;,$2,$3}'|[$1 &quot; &quot; $2] +=$3} END {for(i in combo) print i, combo[i]}'&gt; combos.20201001.txt
  </code></pre>
  <p>In the log being parsed the fields are:</p>
  <ol>
  <li>IP address</li>
  <li>FQDN</li>
  <li>Count</li>
  </ol>
  <p>&quot;</p>
  <pre><code>An input file consisting of: 
  1.2.3.5 four.three.two.com 14
  1.2.3.5 four.three.two.com 34
  1.2.3.5 different.biz 12
  7.8.9.1 four.three.two.com 5
  
  
  should output:
  .biz.different 1.2.3.5 12
  .com.two.three 1.2.3.5 48
  .com.two.three 7.8.9.1 5
  </code></pre>
  <p>&quot;</p>
  <p>The order of the lines output is not important (a job for sort) and the only reason the abbreviated FQDN has been moved from the middle to the front of the line is that is the only way I could get my awk to output the three fields on the same line.</p>
  <p>&quot;</p>
  <pre><code>1.2.3.5 .biz.different 12
  1.2.3.5 .one.two.three 48
  7.8.9.1 .one.two.three 5
  </code></pre>
  <p>&quot;</p>
  <p>Would be acceptable, even preferable.
  Apologies for the formatting; it's somewhat of challenge.</p>