<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Aggregation script needed - awk in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/aggregation-script-needed-awk/m-p/5294307#M59924</link>
    <description>&lt;P&gt;Thanks much for the solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had thought of the procedure but was wandering if there wasn't an even quicker way... doesn't always pay to be lazy.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As for the documentation, yes I did google awk. But again, as you said, there are very numerous hits returned and too many not related to my query.&amp;nbsp; I got fedup looking through them and was asking for a shortcut.&amp;nbsp; I had extracted a nice one yesars ago but lost it when my machine went TU a few months ago.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;RayB&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS, How do we assign points with this new forum?&amp;nbsp;&amp;nbsp; or is this a thing of the past?&lt;/P&gt;&lt;P&gt;RB&lt;/P&gt;</description>
    <pubDate>Mon, 08 Aug 2011 14:10:08 GMT</pubDate>
    <dc:creator>Raynald Boucher</dc:creator>
    <dc:date>2011-08-08T14:10:08Z</dc:date>
    <item>
      <title>Aggregation script needed - awk</title>
      <link>https://community.hpe.com/t5/operating-system-linux/aggregation-script-needed-awk/m-p/5293101#M59921</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a file containing transaction ids and times ex.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;﻿﻿aaaa1 30 ms&lt;/P&gt;&lt;P&gt;aaaa1 40 ms﻿﻿&lt;/P&gt;&lt;P&gt;aaaa1 50 ms&lt;/P&gt;&lt;P&gt;bbbb1 40 ms&lt;/P&gt;&lt;P&gt;bbbb1 60 ms&lt;/P&gt;&lt;P&gt;bbbb1 200 ms﻿&lt;/P&gt;&lt;P&gt;etc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to produce a report like:&lt;/P&gt;&lt;P&gt;aaaa1 3(count) 120 (tot) 40 (avg) 30 (min) 50 (max)&lt;/P&gt;&lt;P&gt;bbbb1 3(count) 300 (tot) 100 (avg) 40 (min) 200 (max)&lt;/P&gt;&lt;P&gt;etc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there and easy way to do this with awk?&lt;/P&gt;&lt;P&gt;I searched but could not find a way to group the lines so I can use the sum, avg, min and max functions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd also like to know where I can find a nice tutorial for awk.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rayb&lt;/P&gt;</description>
      <pubDate>Fri, 05 Aug 2011 19:30:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/aggregation-script-needed-awk/m-p/5293101#M59921</guid>
      <dc:creator>Raynald Boucher</dc:creator>
      <dc:date>2011-08-05T19:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregation script needed - awk</title>
      <link>https://community.hpe.com/t5/operating-system-linux/aggregation-script-needed-awk/m-p/5293137#M59922</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use awk's associative arrays to easily do the grouping.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At the end, use : for &amp;lt;var&amp;gt; in &amp;lt;array&amp;gt; to loop over the keys.&lt;/P&gt;&lt;P&gt;(edited to add comments)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;{ if (0 == count[$1]++) { # First time count is zero. 
     sum[$1] = $2;
     min[$1] = $2; 
     max[$1] = $2;
  } else { # not the first time, work with old values.
    sum[$1] += $2;
    if ($2 &amp;gt; max[$1]) max[$1] = $2;
    if ($2 &amp;lt; min[$1]) min[$1] = $2; 
  }
}
END {
      printf ("%10s %5s %8s %5s %5s %5s\n", "Gizmo", "Count", "tot", "avg", "min", "max");
      printf ("%10s %5s %8s %5s %5s %5s\n", "-----", "-----", "---", "---", "---", "---");

   for (x in count) { # Main reporting loop driven by keys in array
 
      printf ("%10s %5d %8d %5d %5d %5d\n",
              x, count[x], sum[x], sum[x]/count[x], min[x], max[x])
   }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;usage example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;$ cat tmp.txt
aaaa1 30 ms
aaaa1 40 ms
aaaa1 50 ms
bbbb1 40 ms
bbbb1 60 ms
bbbb1 200 ms

Administrator@DX2200-HEIN /cygdrive/c/temp
$ awk -f tmp.awk tmp.txt
     Gizmo Count      tot   avg   min   max
     ----- -----      ---   ---   ---   ---
     aaaa1     3      120    40    30    50
     bbbb1     3      300   100    40   200&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Good luck,&lt;/P&gt;&lt;P&gt;Hein&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Aug 2011 20:15:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/aggregation-script-needed-awk/m-p/5293137#M59922</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2011-08-05T20:15:10Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregation script needed - awk</title>
      <link>https://community.hpe.com/t5/operating-system-linux/aggregation-script-needed-awk/m-p/5293139#M59923</link>
      <description>&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;SPAN class="Apple-style-span"&gt;&lt;FONT color="#666666" size="3"&gt;&lt;SPAN class="Apple-style-span"&gt;&lt;FONT color="#000000"&gt;&amp;gt;&amp;gt; I'd also like to know where I can find a nice tutorial for awk.﻿&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;SPAN class="Apple-style-span"&gt;&lt;FONT color="#666666" size="3"&gt;&lt;SPAN class="Apple-style-span"&gt;&lt;FONT color="#000000"&gt;I'm please to see you ask, but... has google stopped working for you?&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;SPAN class="Apple-style-span"&gt;&lt;FONT color="#666666" size="3"&gt;&lt;SPAN class="Apple-style-span"&gt;&lt;FONT color="#000000"&gt;If I feed that whole line, or just "awk tutorial" into google it comes back with many good suggestions.&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;SPAN class="Apple-style-span"&gt;&lt;FONT color="#666666" size="3"&gt;&lt;SPAN class="Apple-style-span"&gt;&lt;FONT color="#000000"&gt;There are also many AWK books.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;SPAN class="Apple-style-span"&gt;&lt;FONT color="#666666" size="3"&gt;&lt;SPAN class="Apple-style-span"&gt;&lt;FONT color="#000000"&gt;I would want (and have) the original book, written the mr's A, W and K.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;SPAN class="Apple-style-span"&gt;&lt;FONT color="#666666" size="3"&gt;&lt;SPAN class="Apple-style-span"&gt;&lt;FONT color="#000000"&gt;"The AWK Programming Language"by Alfred V. Aho, Brian W. Kernighan, and Peter J. Weinberger.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;SPAN class="Apple-style-span"&gt;&lt;FONT color="#666666" size="3"&gt;&lt;SPAN class="Apple-style-span"&gt;&lt;FONT color="#000000"&gt;Addison-Wesley, 1988.&amp;nbsp;ISBN 0-201-07981-X.﻿ &amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;SPAN class="Apple-style-span"&gt;&lt;FONT color="#666666" size="3"&gt;&lt;SPAN class="Apple-style-span"&gt;&lt;FONT color="#000000"&gt;It is oddly expensive though, and surely there are better books for less money 20+ years later&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;SPAN class="Apple-style-span"&gt;&lt;FONT color="#666666" size="3"&gt;&lt;SPAN class="Apple-style-span"&gt;&lt;FONT color="#000000"&gt;Cheers,&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;SPAN class="Apple-style-span"&gt;&lt;FONT color="#666666" size="3"&gt;&lt;SPAN class="Apple-style-span"&gt;&lt;FONT color="#000000"&gt;Hein﻿&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#666666" size="3"&gt;&lt;SPAN class="Apple-style-span"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Aug 2011 20:25:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/aggregation-script-needed-awk/m-p/5293139#M59923</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2011-08-05T20:25:54Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregation script needed - awk</title>
      <link>https://community.hpe.com/t5/operating-system-linux/aggregation-script-needed-awk/m-p/5294307#M59924</link>
      <description>&lt;P&gt;Thanks much for the solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had thought of the procedure but was wandering if there wasn't an even quicker way... doesn't always pay to be lazy.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As for the documentation, yes I did google awk. But again, as you said, there are very numerous hits returned and too many not related to my query.&amp;nbsp; I got fedup looking through them and was asking for a shortcut.&amp;nbsp; I had extracted a nice one yesars ago but lost it when my machine went TU a few months ago.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;RayB&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS, How do we assign points with this new forum?&amp;nbsp;&amp;nbsp; or is this a thing of the past?&lt;/P&gt;&lt;P&gt;RB&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2011 14:10:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/aggregation-script-needed-awk/m-p/5294307#M59924</guid>
      <dc:creator>Raynald Boucher</dc:creator>
      <dc:date>2011-08-08T14:10:08Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregation script needed - awk</title>
      <link>https://community.hpe.com/t5/operating-system-linux/aggregation-script-needed-awk/m-p/5294313#M59925</link>
      <description>&lt;P&gt;Points are out, 'kudos' are in.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You may also want to mark the topic, or a specific reply as 'solved', to help future visitors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hein.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2011 14:18:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/aggregation-script-needed-awk/m-p/5294313#M59925</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2011-08-08T14:18:06Z</dc:date>
    </item>
  </channel>
</rss>

