Help with filter result (scientific notation) by using awk

Input file:

data1 0.05
data2 1e-14
data1 1e-330
data2 1e-14
data5 2e-60
data5 2e-150
data1 4e-9

Desired output:

data2 1e-14
data1 1e-330
data2 1e-14
data5 2e-60
data5 2e-150

I would like to filter out those result that column 2 is less than 1e-10.
Command try:

awk '($2 <"1e-10") {print $0}' input_file

I not too sure why the above code no work for certain record that got very small scientific notation in column 2.

Thanks for any advice.

You are comparing them as strings, not numbers. Convert $2 to a number by adding 0 to it, and don't quote your own value.

awk '($2 + 0) < 1E-10' inputfile

You don't need a { print $0 } block. If you leave it off, that's what awk assumes you'd do anyway.

1 Like