Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi there
I'm new to performing calculations using awk or some
such tool withi a UNIX shell script. I have a formula which
I need to calculate. I've done it using bc but it involves
breaking down the formula and performing 8 calculations
which I'm sure isn't the best way to do this! There are
input values to the formula which I have assigned to A, B,
C, D, E and F in the script.The formula is as follows:
Square root of (A-D)^2 + (B-E)^2 + (C-F)^2
where (A-D)^2 equals A-D squared.
BTW all or some of A-F may have negative values!
It doesn't necessarily have to be performed using awk but
the faster the better as I'll have a lot of calculations to do!Thanks for any assistance.
Simon

Here is an awk solution, but you might be better off embeeding your bc solution in a script. I think bc probably has a smaller foot print than awk:
#!/bin/ksh
A=63
D=-1
B=51
E=2
C=89
F=8# should be 24
echo ""|awk '{ print sqrt(A-D)+sqrt(B-E)+sqrt(C-F) }' A=$A D=$D B=$B E=$E C=$C F=$F

![]() |
Awk duplicate record elim...
|
passing value between uni...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |