Addition tools in Bourne
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Addition tools in Bourne




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Addition tools in Bourne  
Adam


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-18-06 03:40 AM

Hi,
In a shell, Bourne in my case, what tools would I use, can how would I
use them to add up a set of numbers in a file.
For example if I had a file holding...

filename
------------
10
15
7
2

How would I derive the total of those numbers, 34?

Any help what-so-ever appreciated.

Thanks
Adam.






[ Post a follow-up to this message ]



    Re: Addition tools in Bourne  
Chris F.A. Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-18-06 03:40 AM

On 2006-02-15, Adam wrote:
> Hi,
> In a shell, Bourne in my case, what tools would I use, can how would I
> use them to add up a set of numbers in a file.
> For example if I had a file holding...
>
> filename
> ------------
> 10
> 15
> 7
> 2
>
> How would I derive the total of those numbers, 34?

See my answer in comp.unix.questions. (The first solution is POSIX
rather than Bourne.)

--
Chris F.A. Johnson, author   |    <http://cfaj.freeshell.org>
Shell Scripting Recipes:     |  My code in this post, if any,
A Problem-Solution Approach  |          is released under the
2005, Apress                 |     GNU General Public Licence





[ Post a follow-up to this message ]



    Re: Addition tools in Bourne  
Jim Cochrane


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-18-06 03:40 AM

In article <1140020571.771822.162140@z14g2000cwz.googlegroups.com>, Adam wrote:
> Hi,
> In a shell, Bourne in my case, what tools would I use, can how would I
> use them to add up a set of numbers in a file.
> For example if I had a file holding...
>
> filename
> ------------
> 10
> 15
> 7
> 2
>
> How would I derive the total of those numbers, 34?

There are many ways to do this - here is a pretty short/easy one:

awk '{sum += $1} END {print sum}' file


--
Jim Cochrane; jtc@dimensional.com
[When responding by email, include the term non-spam in the subject line
 to
get through my spam filter.]





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 03:15 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register