Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messageOn 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
Post Follow-up to this messageBeta 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
}
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.