1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
Option Explicit
Dim FileObj, strLine, fso, f, fc, f1, strOut, strParts, FolderSpec, strOutFileName, objFileOut
If WScript.Arguments.Count <> 2 Then
WScript.Echo "Usage: cscript parser.vbs inpath, outfilename"
WScript.Quit
End If
FolderSpec = WScript.Arguments(0)
strOutFileName = WScript.Arguments(1)
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set objFileOut = fso.createtextfile(strOutFileName)
Set fc = f.Files
strOut = "Device,Interface,PortChannelMember"
For Each f1 in fc
If f1.name <> strOutFileName Then
Set FileObj = fso.opentextfile(folderspec & "\" & f1.name)
While not fileobj.atendofstream
strLine = Trim(FileObj.readline)
If Left(strline,9) = "interface" Then
If strOut <> "" Then
'wscript.echo strOut
objFileOut.writeline strOut
End If
strOut = Left(f1.name,InStrRev(f1.name,".")-1) & "," & Right(strline,Len(strline)-10)
Else
If Left(strline,13) = "channel-group" Then
strParts = split(strline," ")
strOut = strOut & "," & "PC" & strParts(1)
End If
End If
Wend
If strOut <> "" Then
'wscript.echo strOut
objFileOut.writeline strOut
End If
FileObj.close
strOut = ""
End If
Next
objFileOut.close
Set FileObj = nothing
Set objFileOut = nothing
Set fc = nothing
Set f = nothing
Set fso = nothing
|