![]() |
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 |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Unix:mail sending issue..pls help me soon | bobprabhu | UNIX for Dummies Questions & Answers | 2 | 02-01-2008 05:44 AM |
| Unix Login Issue | freakygs | UNIX for Advanced & Expert Users | 1 | 01-16-2008 08:21 AM |
| Issue with Unix cat command | RcR | Shell Programming and Scripting | 13 | 10-31-2007 05:54 AM |
| Unix command mmin issue | Mohee | UNIX for Dummies Questions & Answers | 1 | 08-30-2007 10:41 PM |
| Unix in a Windows environment issue | Aisha Sturkey | UNIX for Dummies Questions & Answers | 6 | 05-02-2005 09:44 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Hi,
I have a shell scripting. This will take 7 digit number in each line and add 7 digit number with next subsequent lines ( normal addition ). Eg: 0000001 0000220 0001235 0000022 0000023 ........... ......... ........ Like this i am having around 1500000 records. After adding , I am getting the result 2147483647 but actual result is 2156379608 . I found the root cause of this issue is that Unix temproary variable can hold only 2156379608 ( Range of integer ) as it's 32 bit. For eg: a=2147483647 expr $a + 2 you will get the negative result. Because while expr working, the result will be stored in internal temporary variable or register then you will get the result.. but that particular temporary variable or register can accomodate only 2147483647 .. if it crosses this limit, you may get the junk value like -ve values... this is my finiding for this issue.. But I want to have resolution for this issue. how to add or do arthimatic opration if i want to have result more than limit ( 2147483647 ). I mean a=2147483647 expr $a + 2 for this i need to get the right result rather than -ve value. |
|
||||
|
This will handle up to 15 signifcant digits:
Code:
awk ' {total+=$0} END { print total} ' file
Code:
#/bin/ksh
total=0
while read value
do
total=$(echo "$value + $total" | bc )
done < file
echo $total
|
|
||||
|
Hi ,
Thanks. We are also using the awk for arthitmatic operation . But we are not getting exepected result. I tried with your code as well. $ awk ' {total+=$0} END { print total} ' hash_column_wrong.txt 2.15638e+09 I got the result in expontial format. But I need the result with all the digits. How to achive this?. Then second method which you shown using the bc calculator is taking more time to complte. So I think awk is the best method. As of now , I am getting result as 2.15638e+09 . but I need to get result like 2156380000 . Please help me. Regards, Thambi |
|
||||
|
Reply..
As I already mentioned, it just contains the 7 digiti number in every row. Like these, this file has around 150000 . We just need to add all the rows..that's all
0000001 0000343 0000001 0001426 0000001 0000718 0000162 0000103 0000021 0000011 0000016 0000312 0000026 0000031 0000005 0000022 0000001 0000001 0011845 0003713 0000001 0000011 0000001 0000001 0000001 ..,., ........ ....... |
|
||||
|
Reply....
When I run the below command
awk '{ print $0 " +\\" }' hash_column_wrong.txt | bc I got below exception.. bundling space exceeded on line 1, bundling space exceeded on line 1, bundling space exceeded on line 1, is it due to \n character that occurs end of the line?. |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| bc, big numbers, gawk, sum by column |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|