TCL提取一些输出

时间:2014-05-05 14:18:00

标签: split tcl

我想要做的是分离原因并处理一些变量。 例: 这是我list.txt中的一行 其中:

example row: *!*~*@217.21.146.130 someone Tachka, kakvo stava proshlqk? 0
someone = handle
*!*~*@217.21.146.130 someone Tachka, kakvo stava proshlqk? 0 = reason

可能会像以前一样:

[foreach line [split [readfile blacklist.txt] \n] {set reason [lrange $list 2 end-1]}]

1 个答案:

答案 0 :(得分:0)

假设您希望将someone作为handle变量的值,并且reason变量应保留Tachka, kakvo stava proshlqk? 0 < / p>

set fh [open blacklist.txt r]
while {[gets $fh line] != -1} {
    set reason [lassign [split $line] ip handle]
    puts "handle = $handle"
    puts "reason = [join $reason]"
}
close $fh

你有:

# Blacklist File:
set blackl(file) "scripts/blacklist.txt"

### CIDR
proc bl:cidr:ban {nick uhost hand chan} {
    global botnick exempt_userflag
    set fh [open blackl(file) r]

你需要:

proc bl:cidr:ban {nick uhost hand chan} {
    global botnick exempt_userflag blackl
    set fh [open $blackl(file) r]

鉴于更新的要求:

set line {*!*~*@217.21.146.130 someone Tachka, kakvo stava proshlqk? 0}
set rest [lassign [split $line] ip handle]
set reason [join [lrange $rest 0 end-1]]
set timeout [lindex $rest end]