how to create script for this formula?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to create script for this formula?
# 1  
Old 05-09-2009
how to create script for this formula?

Hello Unix gurus,
Can anyone tell me the most efficient way to create script for the formula?

Formula:

Ans = 1 - ((Buffer pool data physical reads + Buffer pool xda physical reads + Buffer pool index physical reads + Buffer pool temporary data physical reads + Buffer pool temporary xda physical reads + Buffer pool temporary index physical reads )
/ (Buffer pool data logical reads + Buffer pool xda logical reads + Buffer pool index logical reads + Buffer pool temporary data logical reads + Buffer pool temporary xda logical reads + Buffer pool temporary index logical reads )) * 100%

My input file is....
==================================================
$ cat bphit.txt
Buffer pool data logical reads = 19622675514
Buffer pool data physical reads = 2032513088
Buffer pool temporary data logical reads = 2061535206
Buffer pool temporary data physical reads = 2156609
Asynchronous pool data page reads = 1206874663
Buffer pool data writes = 14270567
Asynchronous pool data page writes = 14226588
Buffer pool index logical reads = 11674823029
Buffer pool index physical reads = 137136399
Buffer pool temporary index logical reads = 0
Buffer pool temporary index physical reads = 0
Asynchronous pool index page reads = 24574557
Buffer pool index writes = 5594544
Asynchronous pool index page writes = 5566653
Buffer pool xda logical reads = 6
Buffer pool xda physical reads = 5
Buffer pool temporary xda logical reads = 0
Buffer pool temporary xda physical reads = 0
Buffer pool xda writes = 0
Asynchronous pool xda page reads = 0
Asynchronous pool xda page writes = 0
==================================================

What will be the most efficient way to achieve this?
# 2  
Old 05-09-2009
if you have Python, here's an alternative
Code:
d={}
for line in open("file"):
    line=line.strip().split(" = ")    
    d[line[0]]=int(line[1])

calculation = 1 - ((d["Buffer pool data physical reads"] + 
d["Buffer pool xda physical reads"] + 
d["Buffer pool index physical reads"] + 
d["Buffer pool temporary data physical reads"] + 
d["Buffer pool temporary xda physical reads"] + 
d["Buffer pool temporary index physical reads"] ) / (d["Buffer pool data logical reads"]+
 d["Buffer pool xda logical reads"] + d["Buffer pool index logical reads"] +
 d["Buffer pool temporary data logical reads"] + 
d["Buffer pool temporary xda logical reads"] + 
d["Buffer pool temporary index logical reads"] )) * 100
print calculation

similar, it can be done with awk. split on "=" using FS, then get them into associative arrays. then do the calculation.
# 3  
Old 05-09-2009
Try this:

Code:
BEGIN {FS="="}
$0 ~ /Buffer pool data logical reads/{n1+=$2;next}
$0 ~ /Buffer pool xda physical reads/{n2+=$2;next}
$0 ~ /Buffer pool index physical reads/{n3+=$2;next}
$0 ~ /Buffer pool temporary data physical reads/{n4+=$2;next}
$0 ~ /Buffer pool temporary xda physical reads/{n5+=$2;next}
$0 ~ /Buffer pool temporary index physical reads/{n6+=$2;next}
$0 ~ /Buffer pool data logical reads/{d1+=$2;next}
$0 ~ /Buffer pool xda logical reads/{d2+=$2;next}
$0 ~ /Buffer pool index logical reads/{d3+=$2;next}
$0 ~ /Buffer pool temporary data logical reads/{d4+=$2;next}
$0 ~ /Buffer pool temporary xda logical reads/{d5+=$2;next}
40 ~ /Buffer pool temporary index logical reads/{d6+=$2;next}
END{
cal=1-((n1+n2+n3+n4+n5+n6)/(d1+d2+d3+d4+d5+d6))*100
print "Value is:",cal
}

cheers,
Devaraj Takhellambam
# 4  
Old 05-09-2009
Thanks guys for your quick reply.

@ghostdog74 : Sorry I dont have Python.

@devtakh :
I really don't understand your code, why would anyone pull the lines from file and put in the script like you mentioned...I still think its not good idea.

Please understand my problem properly.
I have all these contents in a file...I want to have some script to which I can provide this file as input parameter...or anyother logic can do...apart from pulling lines out of the file and putting them in script...
# 5  
Old 05-09-2009
You should be more specific on posting the requirement. Perhapes, define the pattern on how the formulae is to be arrived. It is only when you know the pattern, you can come to a logical conclusion to implement that in a program. So what is the pattern in this case?

Looking more deeply into the file, it appears to me that your numerator part of the formulae contains all the physical reads and the denomenator ones are all the logical reads. If that is the case, then

Code:
awk -F "=" '/physical reads/{p+=$2;next}/logical reads/{l+=$2}END{cal=1-(p/l)*100;print cal}' file


cheers,
Devaraj Takhellambam
# 6  
Old 05-09-2009
Correct working script....
awk -F "=" '/physical reads/{p+=$2;next}/logical reads/{l+=$2}END{cal=(1-(p/l))*100;print cal}' file
# 7  
Old 05-09-2009
Good that its working now. That was perhapes a typo in your original requirement.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

A strange formula

Dear Masters, Kindly need your helps for this issue.. I face a formula as a picture... the input file is A DEPT Vp Vs rho VPperVS ------------------------ ------------ ------------ ------------ 700 151.9218 121.9269 ... (11 Replies)
Discussion started by: ipatah
11 Replies

2. Shell Programming and Scripting

Formula missing in excel after using perl

Hi all, I use "Spreadsheet::ParseExcel::SaveParser" to - read a existing excel file with : $Parser = Spreadsheet::ParseExcel::SaveParser->new(); $HeaderFile = $Parser->Parse("XLS_FILE_ACCESS"); - modify some values in somes cell with : $worksheet->AddCell($row_target,$col_max,... (3 Replies)
Discussion started by: Yom
3 Replies

3. Shell Programming and Scripting

formula missing in excel after using perl

Dear all, I got a template excel file which contains several worksheets. Each worksheet contains some formulas in the cells. I am using the perl script to read a CSV file and then put the data of CSV into template excel file(first worksheet) and then save it as new file name using ... (0 Replies)
Discussion started by: eldonlck
0 Replies

4. Shell Programming and Scripting

Convert Formula to Value

I'm new to Perl, but I need to use it to write into an excel spreadsheet. I want to copy the values of certain cells into a new sheet in the workbook. I'm unsure of how to do this because I don't know how to copy values instead of formulas. Note: by formula I mean '=SUM(A1,A2)' and by value I... (0 Replies)
Discussion started by: AgentSmith88
0 Replies

5. Homework & Coursework Questions

Create script to add user and create directory

first off let me introduce myself. My name is Eric and I am new to linux, I am taking an advanced linux administration class and we are tasked with creating a script to add new users that anyone can run, has to check for the existence of a directory. if the directory does not exist then it has... (12 Replies)
Discussion started by: pbhound
12 Replies

6. Shell Programming and Scripting

Formula to get combination… sum

Formula to get combination Lats say, I have 5 values ID Price 1 5 2 10 3 30 4 5 Resule with Possible combinations will be ID Price 1 5 2 10 3 30 4 5 1+1 10 1+2 15 1+3 35 1+4 10 (1 Reply)
Discussion started by: Amit.Sagpariya
1 Replies

7. UNIX for Dummies Questions & Answers

Formula help

The formula below will calculate a distance in miles between 2 points in excel. Can some put it to work in unix? Lat = 43.335 Lon1 = -70.9884 Lat2 = 43.4829 Lon2 = -71.246 distance... (8 Replies)
Discussion started by: bobo
8 Replies

8. Solaris

formula to get the swap space on a machine

Hello there are different opinions on how to get the swap space on Solaris. some say: swap -s and the space= used + available others say swap -l (donno how they get the swap size) other say 'top' command others say using format command (in print sub-command) Could you please advise on... (1 Reply)
Discussion started by: melanie_pfefer
1 Replies

9. Shell Programming and Scripting

Help with formula in a script

I need some help. I been doing system admin for the last several years and gotten very rusty on scripting. I need to write a script that will take a log entry and do math using two columns of data to create a new column. I am taking the column(#2) that contains the time and the column(#5) that... (3 Replies)
Discussion started by: scottzx7rr
3 Replies

10. UNIX for Advanced & Expert Users

Quadratic Formula Program

I have a question about the program I am making. I finished it, compiled it, and there were no errors. Now when I run it, the comand prompt comes up and there are just 1's and 0's that keep looping over and over again. The program is listed before. If anyone has any suggestions I would greatly... (2 Replies)
Discussion started by: zeek
2 Replies
Login or Register to Ask a Question