tcl - First value from second column with the smallest value from column 1 -


i have file

2  1 12 2 34 1 56 1 45 3 33 2 77 1 83 2 62 3 75 3 

i want take first value second column smallest value column 1 this

2  1 12 2 45 3 

this can done linear scan , little bit of use of associative array, this:

set f [open $filename] foreach line [split [read $f] "\n"] {     # assume: valid tcl list of numbers     lassign $line col1 col2     if {![info exists minima($col2)] || $minima($col2) > $col1} {         set minima($col2) $col1     } } close $f foreach col2 [array names minima] {     puts "$minima($col2) $col1" } 

imposing whatever sorts of parsing, sorting , formatting require left you.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -