0

I am trying to get the results for an exact column, that are greater than 0, and less that 10,000,000.

The file I has as following:

799,799,0,0,,0,0,1,0,0,0,0,1,1,1,1,1,5155,5155,,0.000000
673,273,0,0,,0,0,1,0,0,0,0,1,1,1,1,1,5155,5155,,0.000000
941,741,0,0,,0,0,1,1,0,0,0,0,0,0,0,0,5157,5157,,9999998.140000

The last column could include any value between 0.000000 and 10,000,000.

I need the outputs to be restricted to to the values more than 0, and less than 10,000,000.

I tried the following command:

awk -F"," '$21<"10000000"' | awk -F"," '$21>"0.000000"'

but the outputs of $21 are always 1000.000000

Below a sample of the outputs:

647,790,1,0,,0,0,1,0,0,0,0,1,1,1,1,1,5155,5155,,1000.000000
600,796,1,0,,0,0,1,0,0,0,0,1,1,1,1,1,5300,5300,,1000.000000
950,797,1,0,,0,0,1,0,0,0,0,1,1,1,1,1,5300,5300,,1000.000000

2 Answers 2

1

$21<"10000000" make awk used string comparison instead of number comparison.

Try:

awk -F, '$NF>0 && $NF<10000000' <file

Using $NF always give you the last field, you can add or remove others field independently.

0
1

Here is my answer:

gawk -F"," "$21<10000000 && $21 > 0" a

with this output:

941,741,0,0,,0,0,1,1,0,0,0,0,0,0,0,0,5157,5157,,9999998.140000

I do not understand how your awk is generating the 1000.000000 values, nor how it is able to compare numbers to strings (you quoted the ten million and zero values in your conditions). What system are you using?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .