in reply to comparing numbers from previous lines in a file?

This is a bit trickier than it may seem at first sight. What do you do with the first three lines as you don't have three previous lines to compare them with. And what if there is more than one "bad value".

Perhaps a better approach would be to find the "mode" of all the values, i.e. the most common value, and then compare each value with that.

Update: You can ignore all of this, "mode" is not the way to go