## Computing data in awk

Computing data in awk
# 1
09-11-2009
Computing data in awk

Hello,
I am a newbie in programing. I want to compute the following in awk.
I have the following data file:

ID Value1 Value2 Value3
foly 0.31 0.34 43
jude 0.40 0.11 63
jude 0.53 0.32 34
foly 0.30 0.20 56

I want to take an ID “sade” , then take its value3 which is 23 and divide it with sum of value3 (23+66=89) like 23/89=0.258. then multiply it with value1 and value2 and then sum it.
res=23/89
L1[ID]=L1[ID]+(res * 0.21)
L2[ID]=L2[ID]+(res * 0.45)

Now for the second “sade” record
res=66/89
L1[ID]=L1[ID]+(res * 0.67)
L2[ID]=L2[ID]+(res * 0.49)

Similar calculations for other IDs (jude,foly) as well.
Thank you so much for your help.
Regards,
Ubee

Last edited by ubeejani; 09-11-2009 at 09:30 AM..
 ubeejani View Public Profile for ubeejani Find all posts by ubeejani
# 2
09-11-2009
For clarity can you post desired result. It will help to understand the logic.

---------- Post updated at 01:11 PM ---------- Previous update was at 12:57 PM ----------

Quote:
Originally Posted by ubeejani
... with sum of value3 (23+66=98) ...
Hmm! 23+66=89 in my logic.
 ripat View Public Profile for ripat Find all posts by ripat
# 3
09-11-2009

 cfajohnson View Public Profile for cfajohnson Find all posts by cfajohnson
# 4
09-11-2009
ripat! thanks for the correction.I was in hurry.
For each of the ID I want the following output:

L1[sade]=(resi * 0.21)+ (resj * 0.67) where resi =23/89 and resj =66/89
L2[sade]=(resi * 0.45)+ (resj * 0.49)

L1[foly]=( resi * 0.31)+ (resj * 0.30) where resi =43/99 and resj =56/99
L2[foly]=( resi * 0.34)+ (resj * 0.20)

L1[jude]=( resi * 0.40)+ (resj * 0.53) where resi =63/97 and resj =34/97
L2[jude]=( resi * 0.11)+ (resj * 0.32)

I hope you got the logic.
Thanks a lot.
Regards,
Ubee

---------- Post updated at 04:09 PM ---------- Previous update was at 03:23 PM ----------

cfajohnson !
In this code you didn't consider the value of "res" which is for "sade, res=23/89 and 66/89". Similarly for jude and foly. Please check my last message. I hope you will get my point.
Thank you.
Quote:
Originally Posted by cfajohnson

 ubeejani View Public Profile for ubeejani Find all posts by ubeejani
# 5
09-11-2009
Is this what you are after?

On the sample file given above, it produces this output:

 ripat View Public Profile for ripat Find all posts by ripat
# 6
09-11-2009
Bravo!!!
It is working perfectly.
Thank you ripat and cfajohnson for your time.

Regards,
Ubee
 ubeejani View Public Profile for ubeejani Find all posts by ubeejani
# 7
09-14-2009
 summer_cherry View Public Profile for summer_cherry Find all posts by summer_cherry

## awk --> math-operation in data-record and joining with second file data

Hi! I have a pretty complex job - at least for me! i have two csv-files with meassurement-data: fileA ......

## Computing for linearly-interpolated values using awk

Hi, I want to compute for linearly-interpolated values for my data using awk, any help is highly appreciated. How do I apply the linear interpolation formula to my data in awk given the equation below: x y 15 0 25 0.1633611 35 0.0741623 desired output: linear interpolation at...

## Help with parsing data with awk , eliminating unwanted data

Experts , Below is the data: --- Physical volumes --- PV Name /dev/dsk/c1t2d0 VG Name /dev/vg00 PV Status available Allocatable yes VGDA 2 Cur LV 8 PE Size (Mbytes) 8 Total PE 4350 Free PE 2036 Allocated PE 2314 Stale PE 0 IO Timeout (Seconds) default --- Physical volumes ---...

## Computing the ratio of similar columns in the two files using awk script

Thanks Bartus11 for your help in the following code to compare the two files "t1" and "t2". awk 'NR==FNR{a=1;next}\$2 in a{print \$2}' t1 t2 First can anyone explain that what is the purpose of assigning a =1? Second, the current script is printing out the matched columns between the...

## AWK help. how to compare a variable with a data array in AWK?

Hi all, i have a data array as follows. array=ertfgj2345 array=456ttygkd . . . array=errdjt3235 so number or elements in the array can varies depending on how big the data input is. now i have a variable, and it is \$1 (there are \$2, \$3 and so on, i am only interested in \$1). ...

## Cloud Enabling Computing for the Next Generation Data Center

Hear how the changing needs of massive scale-out computing is driving a transfomation in technology and learn how HP is supporting this new evolution of the web. More...

## Event Cloud Computing - IBM Turning Data Centers Into ?Computing Cloud?

Tim Bass Thu, 15 Nov 2007 23:55:07 +0000 *I predict we may experience less*debates*on the use of the term “event cloud”*related to*CEP in the future, now that both IBM and Google* have made announcements about “cloud computing” and “computing cloud”, IBM Turning Data Centers Into ‘Computing...

## Trusted Computing

About a year ago, a friend of mine who worked on the OReilly Snort book took a propsal he and I had worked on for a book on Trusted Computing. Though the editor thought the content was good and worthwhile, he felt that there wasn't enough of a market to justify printing such a work. How many...