我有這樣如何檢查tcl列表中的相鄰值?
set val [ list Fa2/0/1 Fa2/0/24 Gi1/0/13 Gi1/0/23 Gi1/1/1 Gi2/0/1 ]
列表現在我希望把它放在一個循環,並在每個範圍內執行某些命令
像
set number 0
set pattern 0
foreach n $val {
if {$pattern == 0} {
set current $n
regexp {(.*/)(\d+)} $n - pattern number
continue
}
regexp {(.*/)(\d+)} $n - match1 match2
if {$match1 == $pattern} {
#puts "someproc $current - match2"
}
}
我無法得到這個工作輸出應該像ech對或奇異值一樣發現
someproc Fa2/0/1 - 24
someproc Gi1/0/13 - 23
someproc Gi1/1/1 - 1 #for singular values
someproc Gi2/0/1 - 1
編輯:我有一個像這樣的數據的列表:
Gi3/0/1 Fa2/0/1 Fa2/0/24 Gi1/0/13 Gi1/0/23 Gi1/1/1 Gi2/0/1 Te1/0/1
在那裏你可以說每一個數據可以Gi3/0/
類型或Gi2/0/
或Fa2/0/
這些reperesent每一個類型,我需要一些範圍思科swicth.Now端口的爲範圍執行一些命令。再拿上面的列表我可以得到。
somecommand Gi3/0/1 - 1 # there is only one `Gi3/0/` with number 1.
somecommand Fa2/0/1 - 24 # range of `Fa2/0/` is 1 to 24
同樣,
somecommand Gi1/0/13 - 23
somecommand Gi1/1/1 - 1
and so on
非常感謝@ GIC82 – munish 2013-04-25 13:08:36
什麼是模式($模式,L)我不明白什麼是L和H在這個關聯數組中。 – munish 2013-04-25 13:59:23
這只是我可以說的變量或標籤(不是任何關鍵詞)。我使用這些來獲取相同模式的較低(L)和較高(H)範圍的值。在數組中,我們可以有多個由逗號分隔的鍵。 – GIC82 2013-04-26 05:15:39