Awk with function call error in redirection

advertisements
awk -F "|" 'function decToBin(dec) { printf "ibase=10; obase=2; $dec" | bc; } BEGIN {print $3" "$4" "$5" "$6" "$7" "decToBin($8)}' $Input

where Input is the path to file having

1|2|1.00|0.46|0.44|1.12|49.88|3
2|2|1.00|0.45|0.55|1.13|50.12|11

It was working correctly without function calling but after introducing function decToBin() it gives error. it gives error as

awk: fatal: expression for `|' redirection has null string value

got stuck dont know how to do that please need help


myawkscript.awk:

function decToBin(dec) {
    cmd="echo 'ibase=10; obase=2;" dec ";'|bc";
    cmd|getline var
    return var
}

//{print $3" "$4" "$5" "$6" "$7" "decToBin($8)}

Then

gawk -F"|" -f myawkscript.awk myfile

Gives you

1.00 0.46 0.44 1.12 49.88 11
1.00 0.45 0.55 1.13 50.12 1011

as expected