Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing data in file 1

Status
Not open for further replies.

Corez

Programmer
Feb 9, 2005
2
FI
I need help to make list of top useres.
I have file file.txt and need to parse it.

--- text in file.txt ---

corez 140.40
matt 132.22
jhon 120.33
damon 159.19

--- end of file ---

i need to arrange those lines like

damon 159.19
corez 140.40
matt 132.22
jhon 120.33

there is 200 lines in that file.txt
that first value is $nick and second is $db
those $db values is the thing what puts them in order.
I meet problem when trying parse same values...
So thanks for you time...
 
I would use the list_sort feature as follows:

read the entire file into a list
set fid [open file.txt r]
set linelst [split [read $fid] \n]

split each line into a 2-element list and make that into a list o'lists
foreach line $linelst {lappend usrlst [split $line]}
sort the new list, usrlst, on the second element
set usrlst [lsort -index 1 -real -decreasing $usrlst]
now, in your example, lindex $usrlst 0 will return {damon 159.19}

Bob Rashkin
rrashkin@csc.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top