2012-08-08 88 views
0

下面是文件,格式使用VB腳本文件

 
AMQ8409: Display Queue details. 
    QUEUE(TEST1)   TYPE(QLOCAL) 
    CURDEPTH(0)        MAXDEPTH(1000) 
AMQ8409: Display Queue details. 
    QUEUE(TEST2)    TYPE(QLOCAL) 
    CURDEPTH(0)        MAXDEPTH(5000) 
AMQ8409: Display Queue details. 
    QUEUE(TEST3)   TYPE(QLOCAL) 
    CURDEPTH(0)        MAXDEPTH(5000) 

我需要格式化上述文件,如下,使用VB腳本

 

QUEUE(TEST1) TYPE(QLOCAL) CURDEPTH(0) MAXDEPTH(1000) 
QUEUE(TEST2) TYPE(QLOCAL) CURDEPTH(0) MAXDEPTH(5000) 
QUEUE(TEST3) TYPE(QLOCAL) CURDEPTH(0) MAXDEPTH(5000) 

回答

0

使用您感興趣的部分一個RegExp在:

Dim reX : Set reX = New RegExp 
    reX.Global = True 
    reX.Pattern = "\w+\(\w+\)" 
    Dim sAll : sAll  = goFS.OpenTextFile("..\data\in.txt").ReadAll() 
    WScript.Echo sAll 
    Dim oMTS : Set oMTS = reX.Execute(sAll) 
    Dim nMT 
    For nMT = 0 To oMTS.Count - 1 Step 4 
     WScript.Echo Join(Array(oMTS(nMT + 0), oMTS(nMT + 1), oMTS(nMT + 2), oMTS(nMT + 3))) 
    Next 

輸出:

AMQ8409: Display Queue details. 
    QUEUE(TEST1)   TYPE(QLOCAL) 
    CURDEPTH(0)        MAXDEPTH(1000) 
AMQ8409: Display Queue details. 
    QUEUE(TEST2)    TYPE(QLOCAL) 
    CURDEPTH(0)        MAXDEPTH(5000) 
AMQ8409: Display Queue details. 
    QUEUE(TEST3)   TYPE(QLOCAL) 
    CURDEPTH(0)        MAXDEPTH(5000) 

QUEUE(TEST1) TYPE(QLOCAL) CURDEPTH(0) MAXDEPTH(1000) 
QUEUE(TEST2) TYPE(QLOCAL) CURDEPTH(0) MAXDEPTH(5000) 
QUEUE(TEST3) TYPE(QLOCAL) CURDEPTH(0) MAXDEPTH(5000) 
+0

如何讓它寫入文件而不是WScript.Echo。? – Vignesh 2012-08-09 05:23:24

+0

@Vignesh [Ah,come on!](https://www.google.nl/search?q=vbscript+write+to+file) – AutomatedChaos 2012-08-09 08:45:13