Working out the percentage between two values


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Working out the percentage between two values
# 1  
Old 06-03-2010
Working out the percentage between two values

Hi there,

I am totally new to Unix, I am trying to work out the percentage between two values in a ksh shell script and assign the result to a variable.

Value1=577
Values2=244

So the calculation would be as follows:
((Value1 - Value2) / Value1) * 100

How would I be able to achieve this calulation in a ksh shell script?

I have heard that expr can't handle non-integer values and since the above calculation will result in a non-integer value, what other options would I have?

Any help would be greatly appreciated.

Thank you
# 2  
Old 06-03-2010
One way:
Code:
echo "$Value1" "$Value2" | awk '{print ($1-$2)/$1*100}'

# 3  
Old 06-03-2010
Thank you very much, it works like a bomb

Issue resolved
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get average and percentage non zero value

How to calculate percentage non zero value occurrence base on value col 1 and 2 2017 a 0 2017 a 2 2017 a 4 2017 a 2 2017 a 0 2017 b 2 2017 b 6 2016 a 2 2016 a 2 2016 b 2 2016 b 8 2016 b 0 2016 b 0 2016 c 2 2016 c 2 2016 c 0 i manage to get average # awk '{A++;B+=$3}END{for(X in... (1 Reply)
Discussion started by: before4
1 Replies

2. Shell Programming and Scripting

Working out percentage of memory utilization

Hi there I am middle of writing a script to allow me to see the % of the memory which is being used. When I submit my script I don't get any errors but I just get a blank output. Any pointers? available=`free -m | grep available` if then ... (7 Replies)
Discussion started by: simpsa27
7 Replies

3. UNIX for Beginners Questions & Answers

Working out percentage in shell script

Hi All, I currently have a shell script which is pulling multiple counters from various sources. Due to the counters being cumulative counters I've got some code to work out the delta from the last reading and current which is working fine. The problem i have now is being able to work out the... (8 Replies)
Discussion started by: mutley2202
8 Replies

4. Shell Programming and Scripting

Delete row if both percentage values are equal to zero

Hello, I have compiled a script but I have stucked at one point. Each line contains two pcs of % value and what I want to do is to delete any line if both % values are zero. data: expected output: ow3 should be deleted as both percentage value in related line are equal to zero. ... (2 Replies)
Discussion started by: baris35
2 Replies

5. Shell Programming and Scripting

Lookup field values in two fixed format file in UNIX - not working

I have 2 fixed length files input#1 & input#2. I want to match the rows based on the value in position 37-50 in both files (pos 37-50 will have same value in both files). If any matching record is found then cut the value against company code & Invoice number from input file #1 (position 99 until... (3 Replies)
Discussion started by: Lingaraju
3 Replies

6. Shell Programming and Scripting

Working with CSV files values enclosed with ""

I have a CSV file as shown below "1","SANTHA","KUMAR","SAM,MILLER","DEVELOPER","81,INDIA" "2","KAPIL","DHAMI","ECO SPORT","DEVELOPER","82,INDIA" File is comma delimited.All the field values are enclosed by double quotes. But while using awk or cut, it interprets the comma which is present in... (6 Replies)
Discussion started by: santhansk
6 Replies

7. Shell Programming and Scripting

Working With Values After Decimal

I have two files which have to be compared. One of them has leading & trailing zeroes in certain fields. file1 ---- John,Rambo,20100101,2119.5,3302.39,100.07,22211.0 file2 ---- John,Rambo,20100101,000002119.50,0003302.39,00000.07,000022211.00 I am thinking of using diff to... (10 Replies)
Discussion started by: Sheel
10 Replies

8. UNIX for Dummies Questions & Answers

percentage

How to calculate percentage of two values in unix. (5 Replies)
Discussion started by: venkatesht
5 Replies

9. Shell Programming and Scripting

How to calculate the percentage for the values in column

Hi, I am having the file which contains the following two columns. 518 _factorial 256 _main 73 _atol 52 ___do_global_ctors 170 ___main 52 ___do_g How can calculate the percentage of each value in the first column ? first need to get the sum of the first column and... (3 Replies)
Discussion started by: saleru_raja
3 Replies
Login or Register to Ask a Question