Awk 'if' statement help

Hello all,

I'm very new to this (<5hrs!) please bear with me. My file looks like this

386259.448541 417069.155 154935.157 186.206 162 1 1 8
386259.448551 417068.53 154935.04 186.144 156 1 1 8
386259.448561 417067.911 154934.926 186.175 164 1 1 8
386259.450337 417086.643 154946.483 894.671 0 7 1 13
386259.450704 417083.859 154945.922 893.228 0 7 1 14
386259.451101 417082.752 154945.736 897.596 0 7 1 14

I need to first count the number of, and then remove the whole line, where $4 is > a threshold value (say 300).

I have tried to execute a number of 'if' statements based on posts / tutorials I have found but get syntax errors.

Any help most gratefully received!
Rebecca

limit=300
awk -v lim=$limit '$4>=lim {cnt++; next} 1 ' inputfile > outputfile
1 Like

brilliant - that's just the ticket, thank you very much :smiley:

---------- Post updated at 11:38 AM ---------- Previous update was at 10:47 AM ----------

hello again,

I've just discovered that I also need to apply a lower threshold eg all numbers in $4 below 100 to be removed.

I have tried switching the >< signs but this does not give the required result - is there something that I'm missing?

Thanks for your time,
Rebecca

awk '$4>100 && $4<300' infile
1 Like

That works! thanks!