Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

piping file and providing function

Status
Not open for further replies.

ergy

Technical User
Sep 16, 2009
4
0
0
DE
Hey,
I guess it is very easy what I am trying to do, but I don't know how...

Code:
cat input.dat |awk '{
	function acos(x) { return atan2(sqrt(abs(1-x*x)), x) }
	function asin(x) { return atan2(x, sqrt(abs(1-x*x))) }
	function pi() { return 2*asin(1);}
	gamma=acos(($1*$1)/(2*$3*$1))
	print gamma
}'

That was my idea, but of course it doesn't work. Does someone know how to implement functions while piping an file...?
And sorry for the question, but I am not able to solve it... Thanks for any help,
Ergy
 
The function should be defined outside, eg:
Code:
awk '
function acos(x){return atan2(sqrt(abs(1-x*x)),x);}
function asin(x){return atan2(x,sqrt(abs(1-x*x)));}
function pi(){return 2*asin(1);}
{
	gamma=acos(($1*$1)/(2*$3*$1))
	print gamma
}' input.dat

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top