Round with division command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Round with division command
# 8  
Old 02-15-2007
Version

Linux Version 2.4.20-28.5505.EMC
(gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-98))
# 9  
Old 02-15-2007
no bc package installed

Hi,

I quick search on the internet gives that on REDHAT 7.1 the bc package is not installed by default. This could be the cause that bc is not working for me. I am not allowed to install this software so I need an other way... can u help me?

Regards,

Michel
# 10  
Old 02-15-2007
check hegemaro's post for division without using bc
https://www.unix.com/shell-programming-and-scripting/34892-arithmetic-ksh.html
or
Code:
w3=$( echo $w1 $w2 | awk ' { printf("%.2f", $1 / $2 * 100 ) } ' )

# 11  
Old 02-15-2007
Works

That works... thanks again!! you are a lifesaver
# 12  
Old 02-15-2007
To Soon

I was to quick with my response... I do have a minor problem.. I am getting the command not Found. This is the trace of the code

Code:
++ USERID=5003
echo $LINE | cut -f3 -d\|
+++ echo '|#5003' '|' '229194|1048576|1048576|' '|' '3081|' '0|' '0|' '|'
+++ cut -f3 '-d|'
++ USED= 229194
echo $LINE | cut -f4 -d\|
+++ echo '|#5003' '|' '229194|1048576|1048576|' '|' '3081|' '0|' '0|' '|'
+++ cut -f4 '-d|'
++ SOFT=1048576
echo $LINE | cut -f5 -d\|
+++ echo '|#5003' '|' '229194|1048576|1048576|' '|' '3081|' '0|' '0|' '|'
+++ cut -f5 '-d|'
++ HARD=1048576
$(echo $USED $HARD | awk '{printf ("%.1f", $USED/$HARD*100)}')
echo $USED $HARD | awk '{printf ("%.1f", $USED/$HARD*100)}'
++++ echo 229194 1048576
++++ awk '{printf ("%.1f", $USED/$HARD*100)}'
+++ 100.0
./quota.sh: 100.0: command not found
++ PERCENTAGE=

# 13  
Old 02-15-2007
Code:
echo $USED $HARD | awk '{printf ("%.1f", $1/$2*100)}'

# 14  
Old 02-15-2007
Working

Thanks... I have everything working at the moment!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Round values only when it's numerics

Hi, all I have a field in a file looks like this(hundreds of lines): inf 1.24101 -0.185947 -0.349179 inf 0.126597 0.240142 -0.12031And what I expect is: inf 1.241 -0.186 -0.349 inf 0.127 (7 Replies)
Discussion started by: nengcheng
7 Replies

2. Shell Programming and Scripting

Round up the decimals

Hi All, I would like to do the following in the shell script 561.76 to 562 I tried using this echo 'scale=0; 749 * 75 /100 ' | bc but just returned only 561 Please help me . I appreciate your help Thanks rajeevm (13 Replies)
Discussion started by: rajeevm
13 Replies

3. UNIX for Dummies Questions & Answers

Help in division

hi, The below commands result only the whole number(not giving the decimal values). pandeeswaran@ubuntu:~$ echo 1,2,3,4|sed 's/,/\//g'|bc 0 pandeeswaran@ubuntu:~$ echo 1000,2,3|sed 's/,/\//g'|bc 166 How to make it to return the decimal values? Thanks (5 Replies)
Discussion started by: pandeesh
5 Replies

4. Shell Programming and Scripting

division by zero

Hello, I am searching for a way to calculate for example 10/100 within a shellscript and the result should be 0.1 and not just 0. Every alternative i tried just results 0 Thank you in advance 2retti (6 Replies)
Discussion started by: 2retti
6 Replies

5. Shell Programming and Scripting

Round off the a Decimal value.

HI, I have a script which is used to calculate the Memory & CPU utilization a server. memx=`ssh -l siebel1 ${f} /usr/sbin/prtconf|grep -i 'Memory size'|tr -s " "|/usr/xpg4/bin/awk -F" " '{print $3 * 1024}'` v5=`ssh -l siebel1 ${f} vmstat 1 2 | tail -1 | tr -s " " | /usr/xpg4/bin/awk -v... (3 Replies)
Discussion started by: dear_abhi2007
3 Replies

6. Shell Programming and Scripting

Round with awk

Hi, I have a problem. Basically I dont know how to use awk. I have a script (below) which works fine. What I want to do is somehow "pipe" in the input say 4.5 and have it give the anwer, I dont want ot have to type it in, since it will be running in a script. Any ideas how to do this???? ... (1 Reply)
Discussion started by: AnnaLynn
1 Replies

7. Shell Programming and Scripting

Round the column value :

Hi .... Iam having the file ....in which 3rd column is numerical having 8 decimal part... i want that to cut to 2 decimal part ... Source File : E100|0|19940.10104030|0|1ABC E103|1|19942.10195849|3|0ABC E100|0|19943.10284858|0|1ABC I want to be ...... Reulst: ... (4 Replies)
Discussion started by: satyam_sat
4 Replies

8. Shell Programming and Scripting

round a number

In a shell script - How do I round a decimal number (contained in a variable) to the nearest whole number? (2 Replies)
Discussion started by: achieve
2 Replies

9. Shell Programming and Scripting

round in KSH

Is there an easy way to round a number up in Korn shell? ie. 10.4 --> 11 Thanks. (6 Replies)
Discussion started by: here2learn
6 Replies

10. UNIX for Dummies Questions & Answers

how to round a value

Hello, In a unix shell script,i want to round a variabele to a nearest number Ex: set count=104.4 How can i round that to 105.? Thanks, Sateesh (2 Replies)
Discussion started by: kotasateesh
2 Replies
Login or Register to Ask a Question