Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
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


Report this thread to moderator Post Follow-up to this message
Old Post
Beta
08-13-07 12:57 PM


Re: the smallest value in a row
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


Report this thread to moderator Post Follow-up to this message
Old Post
Vassilis
08-13-07 11:58 PM


Re: the smallest value in a row
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
}


Report this thread to moderator Post Follow-up to this message
Old Post
Thomas Weidenfeller
08-13-07 11:58 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 11:19 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.