How to perform calculations using numbers greater than 2150000000.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to perform calculations using numbers greater than 2150000000.
# 1  
Old 11-21-2005
Question How to perform calculations using numbers greater than 2150000000.

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..
# 2  
Old 11-21-2005
PRODUCT=`echo '2150000000 * 2' | bc`
# 3  
Old 11-22-2005
Question

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
# 4  
Old 11-22-2005
I don't know that the loop's the problem, but can't say for certain - could you exactly how it's not working? Is the expected output different from the actual result?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find a matched pattern and perform comparison on numbers next to it

Hi, I have been trying to extract rows that match pattern "cov" with the value next to it to be > 3. The 'cov' pattern may appear either in $3 or $4 (if using ";" as field separator). Below is the example:- input file ... (7 Replies)
Discussion started by: bunny_merah19
7 Replies

2. UNIX for Advanced & Expert Users

Search for columns with numbers greater than 70

This helped get me started. https://www.unix.com/unix-for-dummies-questions-and-answers/157026-need-command-search-numbers-greater-than-3000-a.html This is the command I am using. I am trying to find numbers greater than 70 in column 5. I do not know if it is getting confused because there... (6 Replies)
Discussion started by: cokedude
6 Replies

3. Shell Programming and Scripting

Filter on one column and then perform conditional calculations on another column with a Linux script

Hi, I have a file (stats.txt) with columns like in the example below. Destination IP address, timestamp, TCP packet sequence number and packet length. destIP time seqNo packetLength 1.2.3.4 0.01 123 500 1.2.3.5 0.03 44 1500 1.3.2.5 0.08 44 1500 1.2.3.4 0.44... (12 Replies)
Discussion started by: Zooma
12 Replies

4. UNIX for Dummies Questions & Answers

Grep lines with numbers greater than 2 digits at the end of the line

I'm trying to grep lines where the digits at the end of each line are greater than digits. Tried this but it will only allow me to specify 2 digits. Any ideas would greatly be appreciated. grep -i '\<\{3,4,5\}\>' file ---------- Post updated at 05:58 PM ---------- Previous update was at 05:41... (1 Reply)
Discussion started by: jimmyf
1 Replies

5. Shell Programming and Scripting

How to search for numbers greater than x?

I have a file with multiple fields, example below File 1: Field 1|Field 2|Field 3|Field 4|Field 5|Field 6|Field 7|100 Field 1|Field 2|Field 3|Field 4|Field 5|Field 6|Field 7|101 Field 1|Field 2|Field 3|Field 4|Field 5|Field 6|Field 7|102 Field 1|Field 2|Field 3|Field 4|Field 5|Field... (4 Replies)
Discussion started by: castrojc
4 Replies

6. UNIX for Dummies Questions & Answers

need a command to search for numbers greater than 3000

i have a file contains: 13213,A,300 3423,C,200 5563,A,201 3000,A,400 3000,A,402 3000,A,206 3000,A,303 3000,A,200 4233,N,204 i need to search for numbers in the first column are greater than 3000? i have another issue if you can help me? if i want to search in the second or the... (7 Replies)
Discussion started by: takyeldin
7 Replies

7. UNIX for Dummies Questions & Answers

help with doing calculations on data

Dear All, I have a long list like this: 337 375 364 389 443 578 1001 20100 . . . . etc I would like to substract each value from the first entry which in this case is 337 and report it in a separate column. So the expected output looks like 337 0 (10 Replies)
Discussion started by: pawannoel
10 Replies

8. Shell Programming and Scripting

Sed or awk script to remove text / or perform calculations from large CSV files

I have a large CSV files (e.g. 2 million records) and am hoping to do one of two things. I have been trying to use awk and sed but am a newbie and can't figure out how to get it to work. Any help you could offer would be greatly appreciated - I'm stuck trying to remove the colon and wildcards in... (6 Replies)
Discussion started by: metronomadic
6 Replies

9. Shell Programming and Scripting

replacing numbers greater than 0 with 1

I have some ASCII files containing numerous numbers. What I'd like to do is replace all numbers greater than 0 with 1. Examples of the numbers include: - 000011 and 000042 Thanks (4 Replies)
Discussion started by: vrms
4 Replies

10. Solaris

How to perform addition of two numbers in shell scripting in Solaris-10

Hi, I have a sh script which contains the following line TOTAL=$((e4-s4)) -> Where e4 and s4 are input got from the user. At the time of execution of this line the following error occurs test.sh: syntax error at line 8: `TOTAL=$' unexpected How to solve this issue?. Can any... (9 Replies)
Discussion started by: krevathi1912
9 Replies
Login or Register to Ask a Question