Hi,
I have a text file containing numbers. There are up to 6 numbers per row and I need to read them, check if they are 0 and if they are not zero check if they are within a given interval (min,max). If they exceed the max or min they should be set to max or min respectively, if they are in the interval they retain their values.
I have done this with Excel but it is quite dull. Is there a way that you can think of without writing a C program?
This is an example of the input
awk -v min=0.001 -v max=1000.0 '{
$1 = $1 # the same formating for all lines
for (i=1; i<=NR; i++)
if ($i)
if ($i < min) $i = min
else if ($i > max) $i = max
print
}' INPUTFILE
You can change OFS and OFMT variables to format output of values.
awk -v min=0.001 -v max=1000.0 '{
OFMT="%12.5e"
$1 = $1 # the same formating for all lines
for (i=1; i<=NR; i++)
if ($i)
if ($i < min) $i = min
else if ($i > max) $i = max
print
}' INPUTFILE