Home > Archive > AWK > August 2007 > the smallest value in a row
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
the smallest value in a row
|
|
|
| Hi all,
I have a such input file :
0 0.5 0.3 0.1
10 0.4 0.2 0.3
20 0.8 0.4 0.3
30 0.3 1.0 0.4
and I would like to get an output file as following :
0 0.1 4
10 0.2 3
20 0.3 4
30 0.3 2
where
the first column (output file)= the first column (input file);
the second column (output file)=the smallest values of the second -
the fourth or the last column (input file)
the third column (output file)=which columns of the input file that
contain the smallest values in each row.
Thank you in advance for answering.
Best regards,
Beta
| |
| Vassilis 2007-08-13, 6:58 pm |
| On 13 , 15:55, Beta <ibethim...@yahoo.com> wrote:
> Hi all,
>
> I have a such input file :
>
> 0 0.5 0.3 0.1
> 10 0.4 0.2 0.3
> 20 0.8 0.4 0.3
> 30 0.3 1.0 0.4
>
> and I would like to get an output file as following :
>
> 0 0.1 4
> 10 0.2 3
> 20 0.3 4
> 30 0.3 2
>
> where
> the first column (output file)= the first column (input file);
> the second column (output file)=the smallest values of the second -
> the fourth or the last column (input file)
> the third column (output file)=which columns of the input file that
> contain the smallest values in each row.
>
> Thank you in advance for answering.
>
> Best regards,
> Beta
{
minindex = 2
min = $minindex
for (i = minindex + 1; i <= NF; i++)
if ($i < min) {
minindex = i
min = $minindex
}
print $1, min, minindex
}
Vassilis
| |
| Thomas Weidenfeller 2007-08-13, 6:58 pm |
| Beta wrote:
> Hi all,
>
> I have a such input file :
>
> 0 0.5 0.3 0.1
> 10 0.4 0.2 0.3
> 20 0.8 0.4 0.3
> 30 0.3 1.0 0.4
>
> and I would like to get an output file as following :
>
> 0 0.1 4
> 10 0.2 3
> 20 0.3 4
> 30 0.3 2
{
ndx = 2
m = $ndx
for(i = ndx + 1; i <= NF; i++) {
if(m > $i) {
m = $i
ndx = i
}
}
print $1, m, ndx
}
|
|
|
|
|