![]() |
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 |
| Date Calculations | mitschcg | UNIX for Dummies Questions & Answers | 8 | 03-06-2009 04:40 AM |
| replacing numbers greater than 0 with 1 | vrms | Shell Programming and Scripting | 4 | 06-04-2008 08:40 AM |
| How to perform addition of two numbers in shell scripting in Solaris-10 | krevathi1912 | SUN Solaris | 9 | 11-29-2007 09:36 AM |
| Time Calculations | Nysif Steve | UNIX for Dummies Questions & Answers | 5 | 09-14-2007 09:49 AM |
| Float calculations | sharmavr | UNIX for Dummies Questions & Answers | 1 | 07-26-2006 03:18 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Could someone tell me how to perform calculations using numbers greater than 2150000000 in Korn Shell? When I tried to do it it gave me the wrong answer.
e.g. I have a ksh file with the contents below: --------------------------------- #!/bin/ksh SUM=`expr 2150000000 + 2` PRODUCT=`expr 2150000000 "*" 2` QUOTIENT=`expr 2150000000 / 2` echo The sum is $SUM echo The product is $PRODUCT echo The quotient is $QUOTIENT --------------------------------- It should give 2150000002 for SUM, 4300000000 for PRODUCT and 1075000000 for QUOTIENT but it outputs below: The sum is -2144967294 The product is 5032704 The quotient is -1072483648 Last edited by stevefox; 11-21-2005 at 08:56 PM.. |
|
||||
|
Thanks Perderabo!
I want to use that inside a For Loop but it does not work. Could someone tell me how to do this calculation inside a For Loop? Below is the ksh containing the For Loop (the values of input will be greater than 2150000000): #!/bin/ksh for i in `cut -f1 -d" " input.txt | uniq` do dividend=0 divider=0 for j in `grep $i input.txt | cut -f4 -d" "` do (( divider = divider + j )) done for j in `grep $i input.txt | cut -f5 -d" "` do (( dividend = dividend + j )) done finalresult=$(echo "scale = 4; $dividend/$divider*100" | bc) echo "$i"" ""$finalresult" >> result done |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|