Home > Back-end >  Using erf function on shell script
Using erf function on shell script

Time:07-29

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

CodePudding user response:

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
  • Perl arrays are indexed from 0 (awk indexes fields from 1) so awk $3 becomes Perl $F[2]
  • -l makes Perl add newline after printing

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

  • Related