<?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: AWK problem in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem/m-p/5076657#M439677</link>
    <description>Great people great solution.&lt;BR /&gt;&lt;BR /&gt;I have used first solution from Hein and its working.&lt;BR /&gt;&lt;BR /&gt;I havn't checked other solution. Points given to other solution on basis of improved comments.</description>
    <pubDate>Tue, 30 Oct 2007 06:12:15 GMT</pubDate>
    <dc:creator>SKSingh_1</dc:creator>
    <dc:date>2007-10-30T06:12:15Z</dc:date>
    <item>
      <title>AWK problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem/m-p/5076646#M439666</link>
      <description>I have following input:&lt;BR /&gt;Date       time     utilization&lt;BR /&gt;10/27/2007 00:00    13.82 &lt;BR /&gt;10/27/2007 00:01    20.95   &lt;BR /&gt;10/27/2007 00:02    10.79   &lt;BR /&gt;10/27/2007 00:03    11.78   &lt;BR /&gt;10/27/2007 00:04    11.77   &lt;BR /&gt;10/27/2007 00:05    9.96   &lt;BR /&gt;10/27/2007 00:06    12.69  &lt;BR /&gt;10/27/2007 00:07    18.94  &lt;BR /&gt;10/27/2007 00:08    17.91  &lt;BR /&gt;10/27/2007 00:09    18.00  &lt;BR /&gt;&lt;BR /&gt;desired output to show per 5 min utilization&lt;BR /&gt;10/27/2007 00:00    &lt;AVERAGE of="" 5mins=""&gt; &lt;BR /&gt;10/27/2007 00:05    &lt;AVERAGE of="" 5mins=""&gt;&lt;/AVERAGE&gt;&lt;/AVERAGE&gt;</description>
      <pubDate>Sun, 28 Oct 2007 03:42:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem/m-p/5076646#M439666</guid>
      <dc:creator>SKSingh_1</dc:creator>
      <dc:date>2007-10-28T03:42:23Z</dc:date>
    </item>
    <item>
      <title>Re: AWK problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem/m-p/5076647#M439667</link>
      <description>if you put that data in a file named as file fallowing shell script help you.&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;let cnt=0&lt;BR /&gt;let avg=0&lt;BR /&gt;let sum_util=0&lt;BR /&gt;cat file | while read date time util&lt;BR /&gt;do&lt;BR /&gt;        let sum_util=$sum_util+$util&lt;BR /&gt;        let cnt=$cnt+1&lt;BR /&gt;        if [ $cnt -eq 5 ]; then&lt;BR /&gt;                let gen_avg=$sum_util/5;&lt;BR /&gt;                echo  "$date\t$time\t$gen_avg"&lt;BR /&gt;                let cnt=0&lt;BR /&gt;        fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;my 10 cents please :)</description>
      <pubDate>Sun, 28 Oct 2007 05:08:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem/m-p/5076647#M439667</guid>
      <dc:creator>Hasan  Atasoy</dc:creator>
      <dc:date>2007-10-28T05:08:14Z</dc:date>
    </item>
    <item>
      <title>Re: AWK problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem/m-p/5076648#M439668</link>
      <description>problem is relatively complex&lt;BR /&gt;&lt;BR /&gt;equirement is to take date and time in consideration&lt;BR /&gt;&lt;BR /&gt;so, when solution should work even when input is &lt;BR /&gt;10/27/2006 00:00 13.82 &lt;BR /&gt;10/27/2006 00:01 20.95 &lt;BR /&gt;10/28/2006 00:01 10.79 &lt;BR /&gt;10/28/2006 00:03 11.78 &lt;BR /&gt;10/28/2006 00:04 11.77 &lt;BR /&gt;10/30/2006 00:08 9.96 &lt;BR /&gt;10/30/2006 00:09 12.69 &lt;BR /&gt;10/30/2006 00:10 18.94 &lt;BR /&gt;&lt;BR /&gt;in this case output should &lt;BR /&gt;10/27/2006 00:00 &lt;AVERAGE&gt;&lt;BR /&gt;10/28/2006 00:00 &lt;AVERAGE&gt;&lt;BR /&gt;10/30/2006 00:05 &lt;AVERAGE 9.96=""&gt;&lt;/AVERAGE&gt;&lt;/AVERAGE&gt;&lt;/AVERAGE&gt;</description>
      <pubDate>Sun, 28 Oct 2007 05:46:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem/m-p/5076648#M439668</guid>
      <dc:creator>SKSingh_1</dc:creator>
      <dc:date>2007-10-28T05:46:59Z</dc:date>
    </item>
    <item>
      <title>Re: AWK problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem/m-p/5076649#M439669</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Your question/request has so little definition as not to merit a suggestion until you better define your objective.&lt;BR /&gt;&lt;BR /&gt;Your first post said "...per 5 minute utilization" but your second post showed data with only three, very long hour periods per day.  &lt;BR /&gt;&lt;BR /&gt;Do you want the average of up to five intervals if they are confined to a discrete day?  Is the average simply the sum of the observed values divided by then number of samples?  Or, is the average the sum of the observed values divided by the total time elapsed for the (up to five) samples?&lt;BR /&gt;&lt;BR /&gt;Don't make the reader guess what you think you want.  Post some real input and some manually calculated output to match it.&lt;BR /&gt;&lt;BR /&gt;Lastly, unlike your previous post closures, don't say "thanks, I got it" without indicating _which_ solution satisfied your original question (and why).  Doing so enhances the quality of the thread for those who follow.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Sun, 28 Oct 2007 09:44:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem/m-p/5076649#M439669</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-10-28T09:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: AWK problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem/m-p/5076650#M439670</link>
      <description>Hi james, Thank you for suggestion I will take care of it.&lt;BR /&gt;&lt;BR /&gt;In given poblem the process data collected may vary over time. some times pocess just executed for 1-2 minutes and some time for number of minutes.&lt;BR /&gt;&lt;BR /&gt;Now requirement is to get average utilization fo each completed instance.&lt;BR /&gt;&lt;BR /&gt;for example: I have posted data collection and desired output of solution.</description>
      <pubDate>Sun, 28 Oct 2007 12:23:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem/m-p/5076650#M439670</guid>
      <dc:creator>SKSingh_1</dc:creator>
      <dc:date>2007-10-28T12:23:29Z</dc:date>
    </item>
    <item>
      <title>Re: AWK problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem/m-p/5076651#M439671</link>
      <description>The challenge in awk is to recognize a time range to correspond with a measurement.&lt;BR /&gt;Normally you'd like to use something like PERL's timelocal() function to map to seconds and chop into a range.&lt;BR /&gt;With that it would be easy to see with integer math whether a new record is a certain (5) number of seconds beyond the range or not.&lt;BR /&gt;We can not 'subtract' the string time to see whether 5 seconds have elapsed.&lt;BR /&gt;&lt;BR /&gt;If we may assume that the records are nicely in order, then we may have a string workaround. For each input line we can find the string which corresponds to the begin of a range. &lt;BR /&gt;Now remember the current range.&lt;BR /&gt;If a record no longer has the same range (doesn't matter whether it is the same day or hour still!) then report what was accumulated so far.&lt;BR /&gt;And of course report the last range after the last record read.&lt;BR /&gt;&lt;BR /&gt;For example, check out a potential solution below. (Remove debug information for production version).&lt;BR /&gt;&lt;BR /&gt;$ cat x.awk&lt;BR /&gt;function range_report() {&lt;BR /&gt;  printf ("-- %s %d %5.2f\n", old_range, range_count, range_value/range_count);&lt;BR /&gt;  }&lt;BR /&gt;/^[0-9]+\// { # Starts with a date?&lt;BR /&gt;  split ( $2, x, ":" ); # hours and minutes&lt;BR /&gt;  range = sprintf ("%s %02d:%02d", $1, x[1], 5*int(x[2]/5))&lt;BR /&gt;#  print range, x[1], x[2], $0;&lt;BR /&gt;  if (range == old_range) {&lt;BR /&gt;    range_count++;&lt;BR /&gt;    range_value += $3;&lt;BR /&gt;  } else {&lt;BR /&gt;    if (range_count) range_report();&lt;BR /&gt;    range_count = 1;&lt;BR /&gt;    range_value = $3;&lt;BR /&gt;    old_range = range;&lt;BR /&gt;  }&lt;BR /&gt;}&lt;BR /&gt;END {range_report()}&lt;BR /&gt;$ cat x&lt;BR /&gt;10/27/2007 00:00 13.82&lt;BR /&gt;10/27/2007 00:01 20.95&lt;BR /&gt;10/27/2007 00:02 10.79&lt;BR /&gt;10/27/2007 00:03 11.78&lt;BR /&gt;10/27/2007 00:04 11.77&lt;BR /&gt;10/27/2007 00:05 9.96&lt;BR /&gt;10/27/2007 00:06 12.69&lt;BR /&gt;10/27/2007 00:07 18.94&lt;BR /&gt;10/27/2007 08:28 17.91&lt;BR /&gt;10/27/2007 08:29 18.00&lt;BR /&gt;10/28/2006 00:01 10.79&lt;BR /&gt;10/28/2006 00:03 11.78&lt;BR /&gt;10/28/2006 00:04 11.77&lt;BR /&gt;10/30/2006 00:08 9.96&lt;BR /&gt;10/30/2006 00:09 12.69&lt;BR /&gt;10/30/2006 00:10 18.94&lt;BR /&gt;$ awk -f x.awk x&lt;BR /&gt;-- 10/27/2007 00:00 5 13.82&lt;BR /&gt;-- 10/27/2007 00:05 3 13.86&lt;BR /&gt;-- 10/27/2007 08:25 2 17.95&lt;BR /&gt;-- 10/28/2006 00:00 3 11.45&lt;BR /&gt;-- 10/30/2006 00:05 2 11.32&lt;BR /&gt;-- 10/30/2006 00:10 1 18.94&lt;BR /&gt;&lt;BR /&gt;Hope this helps some,&lt;BR /&gt;Hein van den Heuvel (at gmail dot com)&lt;BR /&gt;HvdH Performance Consulting&lt;BR /&gt;</description>
      <pubDate>Sun, 28 Oct 2007 14:03:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem/m-p/5076651#M439671</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-10-28T14:03:51Z</dc:date>
    </item>
    <item>
      <title>Re: AWK problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem/m-p/5076652#M439672</link>
      <description>"PERFECT" solution hein.&lt;BR /&gt;This is what I was looking for. &lt;BR /&gt;&lt;BR /&gt;Thank you</description>
      <pubDate>Sun, 28 Oct 2007 17:13:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem/m-p/5076652#M439672</guid>
      <dc:creator>SKSingh_1</dc:creator>
      <dc:date>2007-10-28T17:13:21Z</dc:date>
    </item>
    <item>
      <title>Re: AWK problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem/m-p/5076653#M439673</link>
      <description>&lt;!--!*#--&gt;Try the awk construct below. It breaks up the 2nd field into an hour and minute field and it accrues the sum of the last field until a multiple of five comes across in the minute field after which the process is repeated again.&lt;BR /&gt;&lt;BR /&gt;awk '{&lt;BR /&gt;  m=z[split($2,z,":")]&lt;BR /&gt;  h=z[1]&lt;BR /&gt;  v=int(m/5)*5&lt;BR /&gt;  i=(v&amp;lt;10?$1" "h":"0v:$1" "h":"v)&lt;BR /&gt;  p[i]+=$NF&lt;BR /&gt;}END{for(i in p) print i,p[i]/5}' file</description>
      <pubDate>Sun, 28 Oct 2007 22:00:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem/m-p/5076653#M439673</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-10-28T22:00:56Z</dc:date>
    </item>
    <item>
      <title>Re: AWK problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem/m-p/5076654#M439674</link>
      <description>Not bad Sandman! Not bad.&lt;BR /&gt;&lt;BR /&gt;I think the request was for teh average not to divide by 5 (minutes) but by the number of  occurances. An other array is needed for that.&lt;BR /&gt;(or a single array storing a more complex value with sum and count)&lt;BR /&gt; &lt;BR /&gt;Minor comment: I believe you can not exactly control the order of output.&lt;BR /&gt;&lt;BR /&gt;Also, very minor, I would replace the hard-to-read conditional assign of 'i' with a sprintf.&lt;BR /&gt;&lt;BR /&gt;awk '{&lt;BR /&gt;  m=z[split($2,z,":")]&lt;BR /&gt;  h=z[1]&lt;BR /&gt;  i=sprintf ("%s %s:%02d",$1,h,int(m/5)*5)&lt;BR /&gt;  p[i]+=$NF&lt;BR /&gt;  count[i]++&lt;BR /&gt;}END{for(i in p) print i,p[i]/count[i]}' file&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Sun, 28 Oct 2007 23:29:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem/m-p/5076654#M439674</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-10-28T23:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: AWK problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem/m-p/5076655#M439675</link>
      <description>Hi,&lt;BR /&gt;hi Heine, you're rigth, to fic issue about input and order of otput:&lt;BR /&gt;&lt;BR /&gt;awk ' /^[0-9]+\// {&lt;BR /&gt;m=z[split($2,z,":")]&lt;BR /&gt;h=z[1]&lt;BR /&gt;i=sprintf ("%s %s:%02d",$1,h,int(m/5)*5)&lt;BR /&gt;p[i]+=$NF&lt;BR /&gt;count[i]++&lt;BR /&gt;}&lt;BR /&gt;END {for(i in p) print i,p[i]/count[i]}' f1|\&lt;BR /&gt;sort -t "/" -k3 -k1 -k2&lt;BR /&gt;&lt;BR /&gt;Just my .2$&lt;BR /&gt;HTH,&lt;BR /&gt;Art</description>
      <pubDate>Mon, 29 Oct 2007 03:48:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem/m-p/5076655#M439675</guid>
      <dc:creator>Arturo Galbiati</dc:creator>
      <dc:date>2007-10-29T03:48:20Z</dc:date>
    </item>
    <item>
      <title>Re: AWK problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem/m-p/5076656#M439676</link>
      <description>Well Hein and Art thanks for pointing out the subtleties that I overlooked. And yes the sprintf function makes the code legible instead of the ternary operator.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&lt;A href="http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1158441" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1158441&lt;/A&gt;&amp;lt;&lt;BR /&gt;&lt;BR /&gt;BTW solution in above thread is truly "the work of Art" ;)&lt;BR /&gt;&lt;BR /&gt;And here's the improved version of the awk construct I posted earlier.&lt;BR /&gt;&lt;BR /&gt;awk '{&lt;BR /&gt;  m=z[split($2,z,":")]&lt;BR /&gt;  h=z[1]&lt;BR /&gt;  i=sprintf ("%s %s:%.2d",$1,h,int(m/5)*5)&lt;BR /&gt;  p[i]+=$NF&lt;BR /&gt;  c[i]++&lt;BR /&gt;}END{for(i in p) print i,p[i]/c[i] | "sort -t/ -k3,3.4"}' file</description>
      <pubDate>Mon, 29 Oct 2007 11:34:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem/m-p/5076656#M439676</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-10-29T11:34:24Z</dc:date>
    </item>
    <item>
      <title>Re: AWK problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem/m-p/5076657#M439677</link>
      <description>Great people great solution.&lt;BR /&gt;&lt;BR /&gt;I have used first solution from Hein and its working.&lt;BR /&gt;&lt;BR /&gt;I havn't checked other solution. Points given to other solution on basis of improved comments.</description>
      <pubDate>Tue, 30 Oct 2007 06:12:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem/m-p/5076657#M439677</guid>
      <dc:creator>SKSingh_1</dc:creator>
      <dc:date>2007-10-30T06:12:15Z</dc:date>
    </item>
  </channel>
</rss>

