Ok, let's say i have a filename that consists of nicknames and hostnames like this:
nick host
nick host
etc.
How can i get a specific line number from the file, and the matching nick. For example, get the first word (=nick) on line 3.
Code: Select all
proc getnick {file line} {
if {[catch {open "${file}" r} fp]} {
return -1
}
set _T ""
while {![eof $fp]} {
lappend _T [gets $fp]
}
close $fp
if {[llength $_T] < $line} {
return -1
}
return [lindex [split [lindex $_T [expr $line - 1]]] 0]
}