<?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: Adding multiple lines up and getting a total in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/adding-multiple-lines-up-and-getting-a-total/m-p/2989703#M124103</link>
    <description>If the file just contains the single value you could do:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;TOTAL=0&lt;BR /&gt;for i in $(cat file)&lt;BR /&gt;do&lt;BR /&gt;let TOTAL=$TOTAL+$i&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;echo "The total is $TOTAL"&lt;BR /&gt;</description>
    <pubDate>Thu, 05 Jun 2003 12:06:15 GMT</pubDate>
    <dc:creator>Patrick Wallek</dc:creator>
    <dc:date>2003-06-05T12:06:15Z</dc:date>
    <item>
      <title>Adding multiple lines up and getting a total</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/adding-multiple-lines-up-and-getting-a-total/m-p/2989701#M124101</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I have a file that looks like this...&lt;BR /&gt;&lt;BR /&gt;45&lt;BR /&gt;34&lt;BR /&gt;23&lt;BR /&gt;&lt;BR /&gt;What I need to do is add each line up to get a total.&lt;BR /&gt;&lt;BR /&gt;ie for the example above ...&lt;BR /&gt;&lt;BR /&gt;45+34+23 Total = 102&lt;BR /&gt;&lt;BR /&gt;I think I need to use awk for this but cannot remember how.&lt;BR /&gt;&lt;BR /&gt;Any help would be great.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Colin.</description>
      <pubDate>Thu, 05 Jun 2003 12:02:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/adding-multiple-lines-up-and-getting-a-total/m-p/2989701#M124101</guid>
      <dc:creator>Warren griggs</dc:creator>
      <dc:date>2003-06-05T12:02:13Z</dc:date>
    </item>
    <item>
      <title>Re: Adding multiple lines up and getting a total</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/adding-multiple-lines-up-and-getting-a-total/m-p/2989702#M124102</link>
      <description>Try this:&lt;BR /&gt;&lt;BR /&gt;awk 'BEGIN {total=0;} {total=total+$1;} END {print total,"\n";}' &lt;BR /&gt;&lt;BR /&gt;Rgds...Geoff</description>
      <pubDate>Thu, 05 Jun 2003 12:05:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/adding-multiple-lines-up-and-getting-a-total/m-p/2989702#M124102</guid>
      <dc:creator>Geoff Wild</dc:creator>
      <dc:date>2003-06-05T12:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: Adding multiple lines up and getting a total</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/adding-multiple-lines-up-and-getting-a-total/m-p/2989703#M124103</link>
      <description>If the file just contains the single value you could do:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;TOTAL=0&lt;BR /&gt;for i in $(cat file)&lt;BR /&gt;do&lt;BR /&gt;let TOTAL=$TOTAL+$i&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;echo "The total is $TOTAL"&lt;BR /&gt;</description>
      <pubDate>Thu, 05 Jun 2003 12:06:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/adding-multiple-lines-up-and-getting-a-total/m-p/2989703#M124103</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2003-06-05T12:06:15Z</dc:date>
    </item>
    <item>
      <title>Re: Adding multiple lines up and getting a total</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/adding-multiple-lines-up-and-getting-a-total/m-p/2989704#M124104</link>
      <description>awk 'BEGIN {total=0} {total=total+$NF} END {print "Total is : " total} ' filename&lt;BR /&gt;&lt;BR /&gt;Rgds Jarle&lt;BR /&gt;</description>
      <pubDate>Thu, 05 Jun 2003 12:11:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/adding-multiple-lines-up-and-getting-a-total/m-p/2989704#M124104</guid>
      <dc:creator>Jarle Bjorgeengen</dc:creator>
      <dc:date>2003-06-05T12:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: Adding multiple lines up and getting a total</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/adding-multiple-lines-up-and-getting-a-total/m-p/2989705#M124105</link>
      <description>...or...&lt;BR /&gt;&lt;BR /&gt;perl -lne '{$t+=$_}END{print $t}' filename&lt;BR /&gt;&lt;BR /&gt;rgds, Robin</description>
      <pubDate>Thu, 05 Jun 2003 12:14:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/adding-multiple-lines-up-and-getting-a-total/m-p/2989705#M124105</guid>
      <dc:creator>Robin Wakefield</dc:creator>
      <dc:date>2003-06-05T12:14:43Z</dc:date>
    </item>
    <item>
      <title>Re: Adding multiple lines up and getting a total</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/adding-multiple-lines-up-and-getting-a-total/m-p/2989706#M124106</link>
      <description>Perhaps you will like this one ...&lt;BR /&gt;&lt;BR /&gt;echo $(($(cat file | tr '\012' '+')0))&lt;BR /&gt;&lt;BR /&gt;Regards.</description>
      <pubDate>Thu, 05 Jun 2003 12:51:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/adding-multiple-lines-up-and-getting-a-total/m-p/2989706#M124106</guid>
      <dc:creator>Jean-Louis Phelix</dc:creator>
      <dc:date>2003-06-05T12:51:11Z</dc:date>
    </item>
    <item>
      <title>Re: Adding multiple lines up and getting a total</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/adding-multiple-lines-up-and-getting-a-total/m-p/2989707#M124107</link>
      <description>In Unix, there's always several different ways to do any one thing.  You've already got some good ones, here's another:&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;for AMOUNT in `cat $FILE`&lt;BR /&gt;do&lt;BR /&gt;    (( TOTAL = "$TOTAL" + "$AMOUNT" ))&lt;BR /&gt;done&lt;BR /&gt;echo $TOTAL&lt;BR /&gt;&lt;BR /&gt;Chris</description>
      <pubDate>Thu, 05 Jun 2003 17:51:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/adding-multiple-lines-up-and-getting-a-total/m-p/2989707#M124107</guid>
      <dc:creator>Chris Vail</dc:creator>
      <dc:date>2003-06-05T17:51:48Z</dc:date>
    </item>
    <item>
      <title>Re: Adding multiple lines up and getting a total</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/adding-multiple-lines-up-and-getting-a-total/m-p/2989708#M124108</link>
      <description>or yet another way....&lt;BR /&gt;&lt;BR /&gt;number=$(cat file)&lt;BR /&gt;e=0&lt;BR /&gt;for i in $number&lt;BR /&gt;do&lt;BR /&gt;((e=e+$i))&lt;BR /&gt;done&lt;BR /&gt;echo $e&lt;BR /&gt;&lt;BR /&gt;now if you have multiple columns in your file you can just change the value to $number to assign the field you wish to add up.&lt;BR /&gt;&lt;BR /&gt;i.e.&lt;BR /&gt;number=$(cat file | awk '{print $2}')&lt;BR /&gt;&lt;BR /&gt;and the 2nd field would be added&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 05 Jun 2003 18:22:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/adding-multiple-lines-up-and-getting-a-total/m-p/2989708#M124108</guid>
      <dc:creator>John Meissner</dc:creator>
      <dc:date>2003-06-05T18:22:10Z</dc:date>
    </item>
  </channel>
</rss>

