Sponsored Content
Full Discussion: A strange formula
Top Forums Shell Programming and Scripting A strange formula Post 302868287 by Akshay Hegde on Sunday 27th of October 2013 03:40:39 AM
Old 10-27-2013
Try

Code:
$ cat file
    A DEPT        Vp           Vs            rho         VPperVS
 ------------------------ ------------ ------------ ------------
          700     151.9218     121.9269        2.223     3.623484
        700.5      155.016     125.0216        2.223     3.541452
          701      152.842     122.8473        2.223     3.581353

Code:
$ cat test.sh 
#!/bin/bash


awk  '
  NR>2{
            ++n
            vp+=$2; vs+=$3; rho+=$4;Vp_Vs+=($2/$3)^2
            for(i=1;i<=6;i++)A[n,i]=$i
      }

END{
        vpo  = vp/n
        vs0  = vs/n
        rho0 = rho/n
        k    = Vp_Vs/n
    
        printf "Angle" OFS "p" OFS "q" OFS "r" OFS
        for(x=1;x<=n;x++)printf A[x,1] OFS;printf "\n"

for(j=-90;j<=90;j++){
                             p=cos(j)+sin(j)
                             q=-8*k*sin(j)
                             r=cos(j)-(4*k*sin(j))
                             printf j OFS p OFS q OFS r OFS 

           for(i=1;i<=n;i++){
                                   EEI=vpo*rho0*((A[i,2]/vpo)^p) * ((A[i,3]/vs0)^q) * ((A[i,4]/rho0)^r)
                                   printf EEI OFS 
                            }
                                  printf "\n"
                    }

   }' OFS="\t" CONVFMT="%5.3f" OFMT="%.2g" file

Resulting

Code:
$ bash test.sh   
Angle p q r 700 700.5 701 -90 -1.342 11.057 5.080 305.533 392.341 329.344 -89 -0.350 10.637 5.829 304.277 394.452 328.922 -88 0.964 0.438 1.218 336.218 346.599 339.296 -87 1.392 -10.164 -4.512 376.060 299.780 351.326 -86 0.540 -11.421 -6.094 384.115 291.652 353.651 ................................................................. ................................................................. ................................................................. ................................................................. ................................................................. 88 1.035 -0.438 0.780 339.237 342.608 340.241 89 1.370 -10.637 -4.808 378.078 297.708 351.912 90 0.446 -11.057 -5.976 382.905 292.846 353.304

to save $ bash test.sh >test_file.xlsand in text import wizard select tab for separator

Let me know if its helpful for you

Last edited by Akshay Hegde; 10-27-2013 at 05:06 AM.. Reason: format
This User Gave Thanks to Akshay Hegde For This Post:
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. Shell Programming and Scripting

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... (6 Replies)
Discussion started by: Rahulpict
6 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. 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

8. 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

9. 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

10. Solaris

Formula calculate scan rate

Hi There, Just curious here... If there formula to calculate scan rate on solaris? Thanks Edy (3 Replies)
Discussion started by: edydsuranta
3 Replies
All times are GMT -4. The time now is 08:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy