input
0 0 9820373 2069 0 0 11485482
awk '{print ($1/$3) / ($4/$7)}' input
error
Is there any way to fix this problem ?
input
0 0 9820373 2069 0 0 11485482
awk '{print ($1/$3) / ($4/$7)}' input
error
Is there any way to fix this problem ?
are you sure you have typed correct input? Because on my computer it works and results to 0:
>awk '{print ($1/$3) / ($4/$7)}'
0 0 9820373 2069 0 0 11485482
0
Anyway you may check whether the divisor is equal to 0 and skip such lines or produce 0 without performing any divisions.
some of the lines are actually 0.22 or some thing. I'm still getting the same error
Looks like in some reocrds, $3/$7 is missing or zero, you may verify this using below:
awk '{if(!$3 || $3==0 || !$7 || $7==0) print}' input
if you want to have as the result 0 instead of fatal error you may use the following:
>awk '{_div1= $3 ? ($1 / $3) : 0 ; _div2 = $7 ? ( $4 / $7 ) : 0; _res = _div2 ? ( _div1 / _div2 ) : 0 ; print _res }'
0 0 0 0 0 0 0 0 0 0 0 0
0
0.2 0.2 0.2 0.2 0.2 0.2 0.2
1
1 2 3 4 5 6 7 8
0.583333
If you need, I can send you the explanation
May be I haven't explained well enogu. Here is my real example.
I have 73 sets, each set containing 4 columns (example red and blue) and unique header.
input
gName 1_rawcounts 1_KPM 1.ed(all reads) 1_total_length 21_rawcounts 21_KPM 21.ed(all reads) 21_total_length
E3_c1- 0 0 8820373 2069 0 0 11485482 2069
E3_c2- 0 0 8820373 2069 0 0 11485482 2069
E3_c3- 0 0 8820373 2069 0 0 11485482 2069
E3_c4- 0 0 8820373 2069 0 0 11485482 2069
awk '{print ($2/$5) / ($4 / $5) "\t" ($6/$9) / ($8/$9)}' input
needed output
gName 1 21
E3_c1- 0 0
E3_c2- 0 0
E3_c3- 0 0
E3_c4- 0 0
The first line in the file is the header, so you need to skip it
awk 'NR>1{print $1 "\t" ($2/$5) / ($4 / $5) "\t" ($6/$9) / ($8/$9)}' infile
Oh. Got it. Thanx. I have lot of float numbers. like 1.74133e-07.
Is it possible to convert them to normal integers ? Thanx again
I tried the following code to convert float into ineger
awk '{print $0}' OFMS='%.f'
but didn't work.
And i got a new problem. by using the above suggested scripts i couldn't able to divide numbers like this
0.0701754 0.197995
Thanx
Could you provide input and desired output?
input is like this
0.0105263 0.125897
0.0105263 0.125897
0 0.125897
0.0105263 0.125897
0 0.125897
0 0.125897
0 0.125897
0 0.125897
0 0.125897
output should be like this
awk '{print ($2/$1)}' OFMS='%0.f' input >>output
What is the desired output? There are a couple of zero values, what do you want to do if there is a division by zero?
if there is a case that divisible by 0 then the result should be 0
output
1.25...
1.25..
0
0
0
0
0
0
0
Like this?
awk '{print $1?$2/$1:0}' infile
11.9602
11.9602
0
11.9602
0
0
0
0
0
Yes. thank you
You might find this a bit more readable:
awk '{if($1==0)print 0; else print $2/$1}' infile
I'm wondering how did you get rid off float problem ?
What float problem were you experiencing? Could you give an example of that?
I'm getting output like this
4.04149e-06 1.41442e-06
2.88758e-06 3.37641e-06
Is it possible to change them to normal integer format
Do you mean like this, for example?
awk '{printf "%.2f\n",$1?$2/$1:0}' infile