我有缓冲区“showbuffer”。我想得到缓冲区最后一行的第一个字。我怎么做我用Tcl得到它。我试着用split
Showbuffer
Local Time
----------
Jan 10 14:46:09 2014
1389345369 secs 905581000 nano secs since the Epoch
Thank you
我曾经按照命令拆分缓冲区
set splitBuff [split $showbuffer "\n"]
现在我只需要1389345369秒905581000纳秒,因为Epoch可以在其他缓冲区中打印商店
答案 0 :(得分:0)
缓冲区的最后一行是通过以下方式获得的:
set lastLine [lindex [split $buffer "\n"] end]
该行的第一个单词是通过以下方式获得的:
set firstWord [regexp -inline {\S+} $lastLine]
处理线条时,您可能希望先替换空行:
# Apply the substitution in a loop until it doesn't match
while {[regsub -all {\n\s*\n} $buffer "\n" buffer]} {}
一般来说,你得到的话是:
set words [regexp -all -inline {\S+} $theLine]
然后使用lindex
或lassign
来挑选您想要的内容。
lassign $words seconds - nanosecs
puts "got $seconds and $nanosecs"
答案 1 :(得分:0)
如果你想提取" M secs N nano secs形成Epoch"从字符串中无论它在哪里,你都可以:
set showbuffer {Local Time
----------
Jan 10 14:46:09 2014
1389345369 secs 905581000 nano secs since the Epoch
Thank you}
regexp {\d+ secs \d+ nano secs since the Epoch} $showbuffer result
puts $result
1389345369 secs 905581000 nano secs since the Epoch