<?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 ave and max in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/ave-and-max/m-p/3944190#M760682</link>
    <description>Hi Guys,&lt;BR /&gt;I have a file which contains numbers (some of them decimals). For each file has different word count (wc -l). I computed for each the average and maximum value. I did use for loops like for i in `cat file`&lt;BR /&gt;do&lt;BR /&gt;x = `expr $x + i | bc -l`&lt;BR /&gt;done&lt;BR /&gt;x is at initial zero then I use it as well by checking max by "if" logic.&lt;BR /&gt;But it requires time so I may ask if you have any idea how can I use awk in it for the average and maximum values in that file.&lt;BR /&gt;Will appreciate your help. Regards....&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Wed, 14 Feb 2007 01:54:15 GMT</pubDate>
    <dc:creator>Lexxx</dc:creator>
    <dc:date>2007-02-14T01:54:15Z</dc:date>
    <item>
      <title>ave and max</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ave-and-max/m-p/3944190#M760682</link>
      <description>Hi Guys,&lt;BR /&gt;I have a file which contains numbers (some of them decimals). For each file has different word count (wc -l). I computed for each the average and maximum value. I did use for loops like for i in `cat file`&lt;BR /&gt;do&lt;BR /&gt;x = `expr $x + i | bc -l`&lt;BR /&gt;done&lt;BR /&gt;x is at initial zero then I use it as well by checking max by "if" logic.&lt;BR /&gt;But it requires time so I may ask if you have any idea how can I use awk in it for the average and maximum values in that file.&lt;BR /&gt;Will appreciate your help. Regards....&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 14 Feb 2007 01:54:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ave-and-max/m-p/3944190#M760682</guid>
      <dc:creator>Lexxx</dc:creator>
      <dc:date>2007-02-14T01:54:15Z</dc:date>
    </item>
    <item>
      <title>Re: ave and max</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ave-and-max/m-p/3944191#M760683</link>
      <description>&lt;!--!*#--&gt;Assuming one per line:&lt;BR /&gt;awk '&lt;BR /&gt;BEGIN { max=-2000000000; sum=0; count=0 }&lt;BR /&gt;{&lt;BR /&gt;count++&lt;BR /&gt;sum+=$1&lt;BR /&gt;if ($1 &amp;gt; max)&lt;BR /&gt;   max = $1&lt;BR /&gt;}&lt;BR /&gt;END {&lt;BR /&gt;print "average:", sum/count&lt;BR /&gt;print "max:", max&lt;BR /&gt;} ' file&lt;BR /&gt;&lt;BR /&gt;I suppose NR could be used instead of count.</description>
      <pubDate>Wed, 14 Feb 2007 03:53:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ave-and-max/m-p/3944191#M760683</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-02-14T03:53:15Z</dc:date>
    </item>
    <item>
      <title>Re: ave and max</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ave-and-max/m-p/3944192#M760684</link>
      <description>Hi,&lt;BR /&gt;assuming one value per line:&lt;BR /&gt;(/&amp;gt; is my prompt)&lt;BR /&gt;&lt;BR /&gt;/&amp;gt; cat f1&lt;BR /&gt;1.5&lt;BR /&gt;2&lt;BR /&gt;4&lt;BR /&gt;0.5&lt;BR /&gt;0&lt;BR /&gt;&lt;BR /&gt;To get what you need:&lt;BR /&gt;/&amp;gt; sort -nk1 f1|awk '{t+=$1};END {print "Total=" t " Lines=" NR " AVG=" t/NR " MAX=" $1}';&lt;BR /&gt;Total=8 Lines=5 AVG=1.6 MAX=4&lt;BR /&gt;&lt;BR /&gt;I print Total and Lines for debug, but you can avoid this.&lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;Art</description>
      <pubDate>Wed, 14 Feb 2007 05:49:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ave-and-max/m-p/3944192#M760684</guid>
      <dc:creator>Arturo Galbiati</dc:creator>
      <dc:date>2007-02-14T05:49:35Z</dc:date>
    </item>
    <item>
      <title>Re: ave and max</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ave-and-max/m-p/3944193#M760685</link>
      <description>&lt;!--!*#--&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;I don't understand what you mean by&lt;BR /&gt;&amp;gt;&amp;gt;&lt;BR /&gt;For each file has different word count (wc -l)&lt;BR /&gt;&amp;lt;&amp;lt;&lt;BR /&gt;&lt;BR /&gt;Do you have to parse several files, all containing numbers you want to do calculation with? You can use the awk internal variables 'FILENAME' and 'FNR' for this.&lt;BR /&gt;Next: is there only one number per line or do you have multiple entries per line? You would have to&lt;BR /&gt;- loop over all (valid?) fields of line in that case (e.g. for(i=1;i&amp;lt;=NF;i++) ...).&lt;BR /&gt;- add the number of fields instead of using FNR (e.g. num+=NF)&lt;BR /&gt;in that case.&lt;BR /&gt;&lt;BR /&gt;awk 'BEGIN {max="undef"}&lt;BR /&gt;FILENAME &amp;amp;&amp;amp; FILENAME != lastf {printf("max=%s avg=%s\n", max,sum/FNR); max="undef"; sum=0 }&lt;BR /&gt;{lastf=FILENAME; sum+=$1; if(max=="undef") max=$1; else if($1&amp;gt;max) max=$1 }&lt;BR /&gt;END {printf("max=%s avg=%s\n", max,sum/FNR)}' file1 file2 ...&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Wed, 14 Feb 2007 13:17:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ave-and-max/m-p/3944193#M760685</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2007-02-14T13:17:04Z</dc:date>
    </item>
    <item>
      <title>Re: ave and max</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ave-and-max/m-p/3944194#M760686</link>
      <description>&amp;gt;Peter: I don't understand what you mean by&lt;BR /&gt;&lt;BR /&gt;I assumed that the script would have to calculate the number of records and couldn't be a constant.&lt;BR /&gt;</description>
      <pubDate>Thu, 15 Feb 2007 04:29:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ave-and-max/m-p/3944194#M760686</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-02-15T04:29:00Z</dc:date>
    </item>
  </channel>
</rss>

