Your problem is, you should print the head line separately.
to verify it:
kent$ awk 'BEGIN{print "A"/"B"}'
awk: cmd. line:1: fatal: division by zero attempted
You could change your awk line into:
awk 'BEGIN{OFS="\t"} NR==1{print;next}{if ($4==0) {print $0, "inf"} else {print $0, ($3/$4)/log(2)}}' file
I didn't change much in your codes, basically copy and paste, just add the NR==1
part.
NOTE
if you run the code, you will see that the output is not same as your expected (example in your question). I hope your logic ($3/$4)/log(2)
is correct.
the output with NR==1{...}
fix:
ID1 ID2 AVG1 AVG2
ENSG00000207447 RNU6-2 0.101431 0.163308 0.896061
ENSG00000207427 SNORA51 0.096551 0 inf
ENSG00000201784 SNORD14A 0.068653 0.0320985 3.08567
ENSG00000207315 SNORA28 0 0.01936 0
ENSG00000207787 MIR98 0 0 inf