Sum on Sun unix


 
Thread Tools Search this Thread
Operating Systems Solaris Sum on Sun unix
# 1  
Old 01-29-2007
Sum on Sun unix

Hello,

I would like to process a sum on a file :
for exemple :

4
5
3

Sum is 12

I tried with the "+" but it doesn't seems to work on the sun or maybe I use a wrong syntax, my script is as follow:
---------------------------
export Value
export TotalValue

while read Valeur
do
TotalValue= eval $TotalValue + $Value
done < $1

echo $TotalValue
--------------------------------

Thank you for your help!
# 2  
Old 01-29-2007
awk '{c += $0} END{print c}' input_file

Cheers
ZB
# 3  
Old 01-29-2007
Thank you ,

in fact this scripts works :

-------------------------------------
export Valeur=0
export ValeurTotale=0

while read Valeur
do
ValeurTotale=`expr $ValeurTotale + $Valeur`
done < $1

echo $ValeurTotale
----------------------------------------

I have got another problem, it works for numerics without decimals but I need to sum decimals, it seems I need to declare my variables as decimals ? do you know how to do that ?
Does anyone got an idea ????

thank you for your help it's very urgent

Cécile Smilie
# 4  
Old 01-29-2007
Zazzybob !! pleaaaaaaase

I used the awk to sum my file.

it works for "little" sums, but for one file I should have :

25 109 979 252.36

and I have the following result :

9,18618e+08


How should I interpret this result ? is there a limit with the awk calculation?

Thank you for your help Smilie

Cécile
# 5  
Old 01-29-2007
My solution:
Code:
#! /usr/bin/ksh

bc |&
ValeurTotale=0.00

while read Valeur ; do
        print -p $ValeurTotale + $Valeur
        read -p ValeurTotale
done < $1

echo $ValeurTotale
exit 0

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Sun OS 5.5.1 Unix Remote

Hi all, I need some help to remote desktop from Windows to solaris system with SUNOS 5.5.1. I tried to check about XDCMP but all are about the newer system and none mentioning the specific version. I am actually a beginner in all this and I need someone to point me to the right direction. ... (5 Replies)
Discussion started by: Aloft
5 Replies

2. UNIX for Dummies Questions & Answers

Want the UNIX code - I want to sum of the 1st column wherever the first 2nd and 3rd columns r equal

I have the code for the below things.. File1 has the content as below 8859 0 subscriberCreate 18 0 subscriberPaymentMethodChange 1650 0 subscriberProfileUpdate 7668 0 subscriberStatusChange 13 4020100 subscriberProfileUpdate 1 4020129 subscriberStatusChange 2 4020307 subscriberCreate 8831... (5 Replies)
Discussion started by: Mahen
5 Replies

3. UNIX for Dummies Questions & Answers

Unique values in a row sum the next column in UNIX

Hi would like to ask you guys any advise regarding my problem I have this kind of data file.txt 111111111,20 111111111,50 222222222,70 333333333,40 444444444,10 444444444,20 I need to get this file1.txt 111111111,70 222222222,70 333333333,40 444444444,30 using this code I can... (6 Replies)
Discussion started by: reks
6 Replies

4. Shell Programming and Scripting

How To Sum Values Inside One Line In UNIX.?

Dears, Good Day ! Plz; i want to sum-up two consecutive values inside one row, and put the summation in a new column. here the input: 1 2 4 5 6 7 the output should be: 1 2 3 4 5 9 6 7 13 If someone can help me to solve my issue ! thx anyway. Video tutorial on how to use... (5 Replies)
Discussion started by: Ala Alzyadat
5 Replies

5. UNIX for Dummies Questions & Answers

How to add/sum same contents in a unix file

Input 1 2N 2N 1 2N 2N 1 2N 2N 1 2N Ateus 1 3 Mobiles 3M-100 1 3 Mobiles 3M-100 1 3 Mobiles 3M-100 1 3GNET 3gnet 1 3GNET 3gnet 1 3GNET G2828 1 3GNET G2828 1 3GNET G2829 1 3GNET G2829 1 3GNET G2829 OutPut should be 3 2N 2N 3 3 Mobiles 3M-100 2 3GNET 3gnet (4 Replies)
Discussion started by: gagan2010
4 Replies

6. Homework & Coursework Questions

What are the different between UNIX and Sun Solaris OS?

What are the different between UNIX and Sun Solaris OS? could you discuss this in term of the following : memory management, processor, storage management, processing issue, coding issue. ps. thank you :) (0 Replies)
Discussion started by: [-BlackSheep-]
0 Replies

7. Shell Programming and Scripting

Print sum and relative value of the sum

Hi i data looks like this: student 1 Subject1 45 55 Subject2 44 55 Subject3 33 44 // student 2 Subject1 45 55 Subject2 44 55 Subject3 33 44 i would like to sum $2, $3 (marks) and divide each entry in $2 and $3 with their respective sums and print for each student as $4 and... (2 Replies)
Discussion started by: saint2006
2 Replies

8. Shell Programming and Scripting

Difference between cksum and sum in unix

i get 2 different values when i give cksum and sum command. Are they 2 different algorithms? can someone explain how this is different (2 Replies)
Discussion started by: nidhink
2 Replies

9. UNIX for Dummies Questions & Answers

How do you Sum UNIX return codes

Hi, I know how to read a return code after executing a single command. "echo $?". But I do not know how to sum the return code for a group of commands. If I string 3 commands together and I do an echo $? all I get is the retunr code for the last command. Example below: ... (3 Replies)
Discussion started by: z1tt45uuprs7
3 Replies

10. Shell Programming and Scripting

printing file in unix sun os 5.7

Hi, I am trying to print a file with one of the field has over 1000 charactors. When I print the file only part of the data was printed. What can I do to be able to print out all the data in this field? Thanks (3 Replies)
Discussion started by: whatisthis
3 Replies
Login or Register to Ask a Question