![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| cat operation | trichyselva | UNIX for Dummies Questions & Answers | 0 | 03-24-2008 06:55 AM |
| Array operation | phamp008 | Shell Programming and Scripting | 3 | 01-18-2008 05:31 AM |
| Help with arithmetic operation | emjayshaikh | Shell Programming and Scripting | 3 | 09-23-2007 11:44 PM |
| RPC failure on yp operation | Remi | SUN Solaris | 1 | 05-22-2007 10:15 AM |
| AIX 4.3 Openssh 3.7.1.0 Operation | ripley | AIX | 2 | 03-07-2005 01:56 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Problems with sum operation
i wrote this code..
#!/bin/sh sum=0 for i in `cat numbers.txt |cut -f1` do sum=expr $sum + $i done echo $sum I want to read the numbers in the file numbers.txt. and find sum of them. But this code only writes the numbers(without making sum) that it reads. Help me.. |
|
||||
|
Try a bit of awk
burakkilic,
I normally use awk for this kind of problem - it works effectively awk '{tot+=$1} END{print tot}' numbers.txt Alternatively, change your script as shown: #!/bin/sh sum=0 for i in `cat numbers.txt |cut -f1` do sum=`expr $sum + $i` # Add back quotes around the expr done echo $sum Steve |
|
||||
|
Thank you very much!.. The code is working properly
![]() |
| Sponsored Links | ||
|
|