views:

53

answers:

2

In a file 4th column contains a floating point numbers

dsfsd sdfsd sdfds 4.5 dfsdfsd

I want to delete the entire line if the number between -0.1 and 0.1 (or some other range).

Can sed or awk do that for me?

thanks

+3  A: 

awk:

{ if ($4 > 0.1 || $4 < -0.1) print $0 }
VeeArr
+7  A: 

I recommend using the "pattern { expression }" syntax:

awk '($4 < -0.1) || ($4 > 0.1) {print}' test.txt

Or, even more concicely:

awk '($4 < -0.1) || ($4 > 0.1)' test.txt

Since {print} is the default action. I've assumed that you have a file "test.txt" containing your data.

Stuart Lange
This kind of scenario -- line-by-line filtering based on a condition -- is really awk's bread and butter. This was the type of use case that Kernighan et al had in mind when they developed the language. The "pattern {expression}" syntax means that the "{expression}" is executed for a given line if the "pattern" is satisfied for that line.
Stuart Lange