读取特定的行和列使用TCL/TK形成文件

读取特定的行和列使用TCL/TK形成文件,tcl,Tcl,我想用TCL/TK从文件中读取一个单词,并将其存储在变量中 我想读取file.txt中的单词,该文件位于第366行和第19到21列,并将其存储在字符串变量word中 set fp [open src.txt r] set count 0 while {[gets $fp line]!=-1} { incr count if {$count==366} { break } } close $fp puts "Required Line : $lin

我想用TCL/TK从文件中读取一个单词,并将其存储在变量中

我想读取file.txt中的单词,该文件位于第366行和第19到21列,并将其存储在字符串变量word中

set fp [open src.txt r]
set count 0
while {[gets $fp line]!=-1} {
    incr count
    if {$count==366} {
            break
    }
}
close $fp

puts "Required Line : $line"
set result [string range $line 18 20]
puts "Required word(s) : $result"

字符串范围
索引从0开始,因此我在每个索引中减少了1

感谢您的回答。是25号线吗?如何将该字符串存储在变量“Word”中?更新了答案,使其位于第366行,并将其存储在变量
result
中。根据您的需要调整索引。