HELP Script don't work selecting lowest value!!!

Hy again guys,

Last week i resolve a question here but now i need your help again :rolleyes:

I have about 3000 files that i need to choose based on the lowest value, so i make temp files like this:

The files can have lines from 1-10 but only 2 columns, the point is to grep the name os the file in 1st column based in lowest value of 2nd collumn

For select the line with lowest value i use in a bash script this line:

nomepose=(`awk '{if ($2 < min) {min=$2; minline=$0}} END {print minline}' $awkvar | awk '{print $1}'`)

As a awk variable to get me the name of file. But after i execute the script i found that some files have positive values like this:

ZINC03391611_0 0.18602
ZINC03391611_1 3.41902

So when i try that line the script cant copy the name of file with lowest value in this case should had print "ZINC03391611_0" but don't print nothing.

I try some variations in this awk but without sucess.

So how can i make the awk to get me always the lowest value even if the value is positive?! :confused:

Thanks

try this :wink:

# awk '$2~!/^-/{if(NR==1){min2=$2;min=$0;next}{if(min2>$2)min=$0}}END{print min}' infile

Thanks for your reply, in last hour i was try the line you gave me because that line don't get me all files only fews. I'm new in script and after some trys i get this that work:

awk '{if (NR==1){min2=$2; min=$0;next}{if (min2>$2) min=$0}} END {print min}' infile | awk '{print $1}'

The problem is that there are some files that only have 1 column like this:

In this case i DON'T whant the line because there are no value and the awk that i use give me always the low line how can i define the awk for only print the 1st column if there is value in the 2nd?

For what i read about awk i think the 1st part in your line

$2~!/^-/

is for tell to the awk the tipe of the 2nd column right?

About the

(NR==1)

i know this is "The Number of Records Variable" can you please tell me what this do?

Thanks again:b: