Strings to integers in an arithmetic loop

Hi all,

Could someone please advise what is the correct syntax for my little script to process a table of values?

The table is as follows:

0.002432   20.827656
0.006432   23.120364
0.010432   25.914184
0.014432   20.442655
0.018432   20.015243
0.022432   21.579517
0.026432   18.886874
0.030432   18.716673
0.034432   21.537040
0.038432   22.488949
0.042432   22.950917
0.046432   21.831913
0.050432   23.672277
0.054432   22.833953
0.058432   21.612637
0.062432   24.547798
0.066432   18.829130
0.070432   19.830759
0.074432   19.339907
0.078432   18.918358
0.082432   19.867944
0.086432   19.615953
0.090432   15.692428
0.094432   17.568185
0.098432   15.596961
0.102432   16.066848
0.106432   14.792269
0.110432   14.503630
0.114432   12.983533
0.118432   12.873063
0.122432   11.677121
0.126432   12.055901
0.130432   10.980757
0.134432   10.768004
0.138432   10.889363
0.142432   10.769247
0.146432   9.460254
0.150432   10.744807
0.154432   8.657475
0.158432   9.043656
0.162432   9.302273
0.166432   8.663964
0.170432   8.465998
0.174432   8.122258
0.178432   8.019673
0.182432   7.227849
0.186432   7.257996
0.190432   7.329204
0.194432   10.398291
0.198432   6.861956
0.202432   1.074710
0.206432   1.158183

what I want do is to parse this table and print out the value on the left, if the value on the right is less than 2, so desired output for above would be:

0.202432
0.206432

I've got as far as:

for i in `cat table.txt | awk '{ printf "%3.3f\n", $2 }'`; do
    test $i -lt 2 && echo $i
done

but this gives me an "integer expected" error...

Any help much appreciated!

awk '$2<2{print $1}'  file
1 Like

thank you!

---------- Post updated at 01:10 PM ---------- Previous update was at 12:44 PM ----------

What about if a value on the previous line is wanted in output as well? Thanks in advance

What should be the desired output?

0.198432

Something like this?

awk '$2<2{printf("%s%s\n", $1,s?" "s:"");s="";next}{s=$1}' file

nope, that outputs

0.202432 0.198432
0.206432
awk '$2<2{if(s)print s;s="";next}{s=$1}' file

You talk about integers but your input file does not contain integers. Bash, csh, tcsh, ash, dash and more cannot handle floats.

The following works for ksh93 (which can handle floats)

#!/bin/ksh93

while read a b
do
   (( b < 2 )) && echo $a
done < file

Hard to help you here as you have not specified the exact criteria for including a value from a previous line not the expected output format.

Franklin52,

Works great! Thanks a lot (again).