[H-GEN] Shell script problem.

Tom Atkinson tom at tyco.net.au
Thu Jun 4 22:02:22 EDT 1998



On Fri, 5 Jun 1998, Andrae Muys wrote:
> 
> is return the line number of the smallest error.  The problem is that the
> number is a float.  ie.
> 
> 14 3.63234e+07
> 28 3.54324e+07
> 36 3.34564e+07
> 52 3.52345e+07
> 
> Now short of writing a C program to do the final step, can anyone help?

For simplicity, how about the following awk script?  If your data is in
the file "data.file", and the awk script is called "awk.scr", then with
the following command line and "data.file" contents, you get the result
shown:

data.file:

14 3.63234e+07
28 3.54324e+07
52 3.52345e+07
36 3.34564e+03
16 3.00000e+04

command line:

awk -f awk.scr data.file

output:

36 3.34564e+03


awk script:

BEGIN { flag=0 }

{
 if (flag == 0 || $2 < smallest)
    {
     flag = 1;
     smallest = $2;
     lineno = $1;
    }
}           

END { print lineno, smallest }


Cheers,
Tom Atkinson


----------------------- HUMBUG General List --------------------------------
echo "unsubscribe general" | mail majordomo at humbug.org.au # To Unsubscribe



More information about the General mailing list