我来自PERL背景,PowerShell让我很困惑。我有一个交换机配置,我试图确定配置是否存在它不应该存在。
简短的例子:
Dim wb As Workbook
Set wb = ActiveWorkbook
wb.Worksheets("Sheet1").Range("A1").Value = wb.Worksheets("Sheet1").Range("A2").Value
' //'上面的行不在实际文件中。所以"配置块"将来自" ^ interface ....直到!"
这是我到目前为止的代码。
void segregateEvenOdd() {
for (int i = 0; i < endofarray; i++){
int temp;
if (array[i] % 2 == 0) //check if the number is odd or even
temp = array[i];
for(int j = i; j <= endofarray; j++){ //start from 1 cuz we dont want to touch the numbers that are already segregated
array[j] = array[j+1];
}
array[endofarray] = temp;
}
}
我试图将所有配置块添加到列表中以便稍后迭代并找到&#34;最大命令&#34;。
但是上面的代码并没有达到我的预期:
//BAD interface has maximum of 2 but Only 1 learned
interface GigabitEthernet0/0
switchport access vlan 2
switchport mode access
switchport port-security maximum 2
switchport port-security mac-address sticky
switchport port-security mac-address sticky 0050.7966.6800
switchport port-security
media-type rj45
negotiation auto
spanning-tree portfast edge
!
//GOOD default maximum is 1
interface GigabitEthernet0/1
switchport access vlan 2
switchport mode access
switchport port-security mac-address sticky
switchport port-security mac-address sticky 0050.7966.6801
switchport port-security
media-type rj45
negotiation auto
spanning-tree portfast edge
是否有更好的方法来存储所有&#34; Select-String&#34;匹配到列表?
我的下一步是:
$ints = [System.Collections.ArrayList]@()
$file = Get-Content .\router.txt | Out-String
$file | Select-String -Pattern "(?s)interface [etfg][^!]+!" -AllMatches | foreach {$ints.Add($_.Matches.Value)}
我将在~1000个配置文件
上运行它答案 0 :(得分:0)
&#34; out-string&#34;将所有内容放入1个字符串中,而不是数组。因此,当我搜索匹配时,它只是一串值匹配
以下代码将其删除
{{1}}