Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

awk condition with decimal output in if else statement

I am trying to use awk and if else statements simultaneously.

Expression in if else statements are evaluated to a whole number and giving wrong output.

I tried this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

awk '{if ($4/$3 < 0.35) print "reverse"; else if ($3/$4 < 0..35) print "forward"; else print "unstranded" }' <<< "0 207212663 6541998518 259487717"

This is giving reverse as ouput.
correct answer is unstranded

>Solution :

Invert the logic:

$ awk '{
    if ($4/$3 > 0.35) print "reverse"
    else if ($3/$4 > 0.35) print "forward"
    else print "unstranded"
}' <<< "0 207212663 6541998518 259487717"

Disclaimer: As explained in comments, verify that this fits your needs, and it’s not a false positive output.

Output

forward
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading