<?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: about the shell script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/about-the-shell-script/m-p/3102709#M717445</link>
    <description>Hi&lt;BR /&gt;&lt;BR /&gt;Try this&lt;BR /&gt;&lt;BR /&gt;cat abc.txt |grep "^$" |awk '{a+=$NF} END {print a/NR}'&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This will give u avg of n numbers.&lt;BR /&gt;grep "^$" is used to filter blank lines if &lt;BR /&gt;any otherwise which will be also counted as NR.(number of records).&lt;BR /&gt;&lt;BR /&gt;check it out.&lt;BR /&gt;bye&lt;BR /&gt;baiju.</description>
    <pubDate>Mon, 27 Oct 2003 07:36:56 GMT</pubDate>
    <dc:creator>blal</dc:creator>
    <dc:date>2003-10-27T07:36:56Z</dc:date>
    <item>
      <title>about the shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/about-the-shell-script/m-p/3102705#M717441</link>
      <description>&lt;P&gt;I have a text file in shell , how to calculate the average of the it.&lt;BR /&gt;&lt;BR /&gt;#vi abc.txt&lt;BR /&gt;&lt;BR /&gt;10&lt;BR /&gt;20&lt;BR /&gt;30&lt;BR /&gt;40&lt;BR /&gt;&lt;BR /&gt;I want to have the result 25 (100/4) , can suggest how to write the script ? thx.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;P.S. This thread has been moved from HP-UX &amp;gt; System Administration to HP-UX &amp;gt; languages. - Hp ForumModerator&lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2015 08:17:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/about-the-shell-script/m-p/3102705#M717441</guid>
      <dc:creator>juno2</dc:creator>
      <dc:date>2015-03-13T08:17:52Z</dc:date>
    </item>
    <item>
      <title>Re: about the shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/about-the-shell-script/m-p/3102706#M717442</link>
      <description>So long as there are no blank lines in abc.txt, this will work:&lt;BR /&gt;&lt;BR /&gt;cat abc.txt|awk '&lt;BR /&gt;{total+=$1}&lt;BR /&gt;END {printf "Average = %f\n", total/NR}&lt;BR /&gt;'&lt;BR /&gt;&lt;BR /&gt;-- Graham</description>
      <pubDate>Mon, 27 Oct 2003 05:17:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/about-the-shell-script/m-p/3102706#M717442</guid>
      <dc:creator>Graham Cameron_1</dc:creator>
      <dc:date>2003-10-27T05:17:15Z</dc:date>
    </item>
    <item>
      <title>Re: about the shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/about-the-shell-script/m-p/3102707#M717443</link>
      <description>hi &lt;BR /&gt;you can try the following:&lt;BR /&gt;&lt;BR /&gt;sum=0&lt;BR /&gt;avr=0&lt;BR /&gt;for i in `cat abc.txt`&lt;BR /&gt;do&lt;BR /&gt;sum=`expr $sum + $i`&lt;BR /&gt;done&lt;BR /&gt;avr=`expr $sum / 4`&lt;BR /&gt;&lt;BR /&gt;echo $avr&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;NB: use the right single quote "`" NOT "'"&lt;BR /&gt;</description>
      <pubDate>Mon, 27 Oct 2003 06:48:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/about-the-shell-script/m-p/3102707#M717443</guid>
      <dc:creator>TSaliba</dc:creator>
      <dc:date>2003-10-27T06:48:54Z</dc:date>
    </item>
    <item>
      <title>Re: about the shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/about-the-shell-script/m-p/3102708#M717444</link>
      <description>#!/usr/bin/sh&lt;BR /&gt;lines=0&lt;BR /&gt;total=0&lt;BR /&gt;avg=0&lt;BR /&gt;cat abc.txt|while read LINE&lt;BR /&gt;do&lt;BR /&gt;  lines=$(expr $lines + 1)&lt;BR /&gt;  total=$(expr $total + $LINE)&lt;BR /&gt;done&lt;BR /&gt;avg=$(expr $total / $lines)&lt;BR /&gt;echo "Total  : "$total&lt;BR /&gt;echo "Records: "$lines&lt;BR /&gt;echo "Average: "$avg&lt;BR /&gt;&lt;BR /&gt;--Jim</description>
      <pubDate>Mon, 27 Oct 2003 06:59:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/about-the-shell-script/m-p/3102708#M717444</guid>
      <dc:creator>James Specht</dc:creator>
      <dc:date>2003-10-27T06:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: about the shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/about-the-shell-script/m-p/3102709#M717445</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;Try this&lt;BR /&gt;&lt;BR /&gt;cat abc.txt |grep "^$" |awk '{a+=$NF} END {print a/NR}'&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This will give u avg of n numbers.&lt;BR /&gt;grep "^$" is used to filter blank lines if &lt;BR /&gt;any otherwise which will be also counted as NR.(number of records).&lt;BR /&gt;&lt;BR /&gt;check it out.&lt;BR /&gt;bye&lt;BR /&gt;baiju.</description>
      <pubDate>Mon, 27 Oct 2003 07:36:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/about-the-shell-script/m-p/3102709#M717445</guid>
      <dc:creator>blal</dc:creator>
      <dc:date>2003-10-27T07:36:56Z</dc:date>
    </item>
    <item>
      <title>Re: about the shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/about-the-shell-script/m-p/3102710#M717446</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;awk solution seems to be the simpliest one ... but just for your information, doing arithmetic operation is also simple in shell :&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;typeset -i TOT VAR NB&lt;BR /&gt;cat abc.txt | while read VAR&lt;BR /&gt;do&lt;BR /&gt;((TOT=TOT+VAR))&lt;BR /&gt;((NB=NB+1))&lt;BR /&gt;done&lt;BR /&gt;print $((TOT/NB))&lt;BR /&gt;&lt;BR /&gt;Regards.&lt;BR /&gt;</description>
      <pubDate>Mon, 27 Oct 2003 09:11:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/about-the-shell-script/m-p/3102710#M717446</guid>
      <dc:creator>Jean-Louis Phelix</dc:creator>
      <dc:date>2003-10-27T09:11:53Z</dc:date>
    </item>
    <item>
      <title>Re: about the shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/about-the-shell-script/m-p/3102711#M717447</link>
      <description>thx reply, i hv another question , how to find the highest one ? ( the result should be 40) thx in advance .</description>
      <pubDate>Tue, 28 Oct 2003 04:27:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/about-the-shell-script/m-p/3102711#M717447</guid>
      <dc:creator>juno2</dc:creator>
      <dc:date>2003-10-28T04:27:20Z</dc:date>
    </item>
    <item>
      <title>Re: about the shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/about-the-shell-script/m-p/3102712#M717448</link>
      <description>Quite simple...&lt;BR /&gt;&lt;BR /&gt;awk 'BEGIN {max=0;total=0}&lt;BR /&gt;{ total += $1; if (max &amp;lt; $1) {max=$1}}&lt;BR /&gt;END {printf {"Average: %d \t Maximum: %d\n",total/NR,max);}'&lt;BR /&gt;</description>
      <pubDate>Tue, 28 Oct 2003 04:31:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/about-the-shell-script/m-p/3102712#M717448</guid>
      <dc:creator>Elmar P. Kolkman</dc:creator>
      <dc:date>2003-10-28T04:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: about the shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/about-the-shell-script/m-p/3102713#M717449</link>
      <description>Or ...&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;typeset -i TOT VAR NB MAX&lt;BR /&gt;cat a | while read VAR&lt;BR /&gt;do&lt;BR /&gt;((TOT=TOT+VAR))&lt;BR /&gt;((NB=NB+1))&lt;BR /&gt;[[ VAR -gt MAX ]] &amp;amp;&amp;amp; ((MAX=VAR))&lt;BR /&gt;done&lt;BR /&gt;print "Average : $((TOT/NB))   Max : $MAX"&lt;BR /&gt;&lt;BR /&gt;Regards.</description>
      <pubDate>Tue, 28 Oct 2003 04:57:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/about-the-shell-script/m-p/3102713#M717449</guid>
      <dc:creator>Jean-Louis Phelix</dc:creator>
      <dc:date>2003-10-28T04:57:35Z</dc:date>
    </item>
  </channel>
</rss>

