2021年1月23日星期六

Divide all columns by one, line by line, printing NA where division by 0

I have a tab delim file

1A      865     508     512    0       2       0       0  1B      0       0       0      0       0       0       1        

I need to divide every col from $3 on by $2 and multiply the resulting by 100 line by line, printing NA where division by 0.

So that I have

1A  865 58.73  59.19 0.00  0.23  0.00  0.00  0.00  0.00  1B  0   NA     NA    NA    NA    NA    NA    NA    NA  

I tried

awk 'BEGIN{FS=OFS="\t"} FNR>1 {for(i=3;i<=NR;i++) $i={print $0"\t"($2?$i/$2*100:"NaN")1}'  

but I get "unexpected newline or end of string"

https://stackoverflow.com/questions/65866132/divide-all-columns-by-one-line-by-line-printing-na-where-division-by-0 January 24, 2021 at 08:51AM

没有评论:

发表评论