Issue
I am trying to calculate some variables inside awk and most are going well. The single not working is when I try to use erf:
| awk '{print $1, $2, $3, $4, $5, $6, (1365*(erf(6/(2*(1/2)*((1/1250000)*$6*10*10*10*10*10*10*365)))))} '
Does someone know how to help in this trouble?
best, Guilherme
Solution
You can do a virtually 1-1 conversion to Perl:
| perl -MPOSIX=erf -ale 'print join " ", @F[0,1,2,3,4,5],
1365*(erf(6/(2*(1/2)*((1/1250000)*$F[5]*1e6*365)))))'
-a
tells Perl to autosplit lines into array @F-l
makes Perl add newline after printing- Perl arrays are indexed from 0 (awk indexes fields from 1) so awk
$3
becomes Perl$F[2]
@F[0,1,2,3,4,5]
is a list of$F[0]
,$F[1]
, ...join
converts a list into a string using the separator provided. I used this as it seemed a bit neater than typing:print $F[0], " ", $F[1], " ", $F[2], " ", ...
Although it has been removed in more recent versions of Perl, older versions have a helper program a2p
to help with translation from awk (and a similar s2p
for sed).
Answered By - jhnc Answer Checked By - Katrina (WPSolving Volunteer)