set spofile [open test.txt a+]
while { [gets $spofile line] >= 0 } {
incr line_no
if { $line_no == 4 } {
puts " i have read in line 4"
}
}
That's the way to do it.
or
set line_no 4
set spofile [open test.txt a+]
for {set i 1} {$i <= $line_no} {incr i} { gets $spofile line ; }
That's not so good if you have a file with only three lines in it. :^)
Lim's solution is best for text files. You can do better than that if
you have files where every line is the same length, since then you can
use [seek] to go to exactly the right spot, but that doesn't work with
variable-length records (or not without a separate index file, which
makes everything quite a bit more complex.)
Donal.
Just so everyone knows, this question was asked in couple of places so
to consolidate the different answers: