Hello everybody. I am new to VBS and to using RegExp. I have a collection script that grabs data from a Passport switch into multipliable files. I need to parse the data in the files. I put together a function to do this based on what I have found in this forum and the following link: Below is the function and examples of the files and the end result after the files are parsed. The function apears to work fine but I am sure there is something I am missing in the RegExp. Could you look at what I have and tell me if there is a better way. Also thanks for all the info on the this forum
Files before parsing:
File1:
617>
617> d -o laps/*
Laps/*
Use -noTabular to see hidden attributes: osiUnknw, osiStby, osiAlarm,
osiCntrl, osiProc, osiAvail, ps, psmAlarm, mmAlarm, pfAlarm and
timeUntilRestore.
+=====+-----+----+-----+------+------+------+------+------+-------+-----------
|Laps |osiAd|osiO|osiUs|neRxLi|neReq |neReqC|feReq |feReqC|sdOnLin|switchovers
| | min |per | age | ne | | han | | han | es |
+=====+-----+----+-----+------+------+------+------+------+-------+-----------
| 1000|unlck|ena |busy |workin|noRequ|protec|noRequ|protec| | 2
| 1001|unlck|ena |busy |workin|noRequ|protec|noRequ|protec| | 0
| 1002|unlck|ena |busy |workin|noRequ|protec|noRequ|protec| | 0
| 1003|unlck|ena |busy |workin|noRequ|protec|noRequ|protec| | 0
| 1200|unlck|ena |busy |workin|noRequ|protec|noRequ|protec| | 6
| 1300|unlck|ena |busy |workin|noRequ|protec|doNotR|protec| | 0
ok 2007-11-22 22:45:58.21
File2:
618>
618> d -o laps/* sts/*
Laps/* Sts/*
Use -noTabular to see the many hidden attributes.
+=====+===+-----+----+-----+------+---+---+---+---+---+---+----------
|Laps |Sts|osiAd|osiO|osiUs|snmpOp|lop|ais|rfi|slm|txA|txR| pefs
| | | min |per | age |erStat| | | | |is |di |
| | | | | | us | | | | | | |
+=====+===+-----+----+-----+------+---+---+---+---+---+---+----------
| 1000| 0|unlck|ena |busy |up |off|off|off|off|off|off| 1656189
| 1001| 0|unlck|ena |busy |up |off|off|off|off|off|off| 1656191
| 1002| 0|unlck|ena |busy |up |off|off|off|off|off|off| 1656189
| 1003| 0|unlck|ena |busy |up |off|off|off|off|off|off| 1656189
| 1200| 0|unlck|ena |busy |up |off|off|off|off|off|off| 886195
| 1300| 0|unlck|ena |busy |up |off|off|off|off|off|off| 568069
ok 2007-11-22 22:45:59.84
Files after parsing:
File1:
1000;unlck;ena;busy;workin;noRequ;protec;noRequ;protec;;2
1001;unlck;ena;busy;workin;noRequ;protec;noRequ;protec;;0
1002;unlck;ena;busy;workin;noRequ;protec;noRequ;protec;;0
1003;unlck;ena;busy;workin;noRequ;protec;noRequ;protec;;0
1200;unlck;ena;busy;workin;noRequ;protec;noRequ;protec;;6
1300;unlck;ena;busy;workin;noRequ;protec;doNotR;protec;;0
ok2007-11-2222:45:58.21
File2:
1000;0;unlck;ena;busy;up;off;off;off;off;off;off;1656189
1001;0;unlck;ena;busy;up;off;off;off;off;off;off;1656191
1002;0;unlck;ena;busy;up;off;off;off;off;off;off;1656189
1003;0;unlck;ena;busy;up;off;off;off;off;off;off;1656189
1200;0;unlck;ena;busy;up;off;off;off;off;off;off;886195
1300;0;unlck;ena;busy;up;off;off;off;off;off;off;568069
ok2007-11-2222:45:59.84
Here is the function, I am loading the file then reading each line.
===============================================
Function FileParser (filenme)
' On Error Resume Next
Dim regExp1 : Set regExp1 = New RegExp
regExp1.Pattern = "(|)?\d+.(|)?"
regExp1.IgnoreCase = True
Set filEtextFile = filesys.GetFile(filenme)
Set testFile = filEtextFile.OpenAsTextStream(ForReading)
Report="" 'the idea to be proper requires reset to empty'
Do Until testFile.AtEndOfStream
varLine = testFile.ReadLine
If (regExp1.Test(varLine)) And (Len(Trim(varLine)) > 5) And (InStr(varLine, ">") = False) Then
If (Left(varLine,1) = "|") Then
Report = Report & Mid(Trim(varLine),2) & vbCrLf
Else
Report = Report & Trim(varLine) & vbCrLf'
End If
End If
Loop
Do While Instr(Report, " ")
Report = Replace(Report, " ", "")
Loop
'Change delimiter
Report = Replace(Report, "|", ";")
''''''''''Write the changed text back to the file
Set testFile = filEtextFile.OpenAsTextStream(ForWriting)
testFile.Write Report
testFile.Close
End Function
Files before parsing:
File1:
617>
617> d -o laps/*
Laps/*
Use -noTabular to see hidden attributes: osiUnknw, osiStby, osiAlarm,
osiCntrl, osiProc, osiAvail, ps, psmAlarm, mmAlarm, pfAlarm and
timeUntilRestore.
+=====+-----+----+-----+------+------+------+------+------+-------+-----------
|Laps |osiAd|osiO|osiUs|neRxLi|neReq |neReqC|feReq |feReqC|sdOnLin|switchovers
| | min |per | age | ne | | han | | han | es |
+=====+-----+----+-----+------+------+------+------+------+-------+-----------
| 1000|unlck|ena |busy |workin|noRequ|protec|noRequ|protec| | 2
| 1001|unlck|ena |busy |workin|noRequ|protec|noRequ|protec| | 0
| 1002|unlck|ena |busy |workin|noRequ|protec|noRequ|protec| | 0
| 1003|unlck|ena |busy |workin|noRequ|protec|noRequ|protec| | 0
| 1200|unlck|ena |busy |workin|noRequ|protec|noRequ|protec| | 6
| 1300|unlck|ena |busy |workin|noRequ|protec|doNotR|protec| | 0
ok 2007-11-22 22:45:58.21
File2:
618>
618> d -o laps/* sts/*
Laps/* Sts/*
Use -noTabular to see the many hidden attributes.
+=====+===+-----+----+-----+------+---+---+---+---+---+---+----------
|Laps |Sts|osiAd|osiO|osiUs|snmpOp|lop|ais|rfi|slm|txA|txR| pefs
| | | min |per | age |erStat| | | | |is |di |
| | | | | | us | | | | | | |
+=====+===+-----+----+-----+------+---+---+---+---+---+---+----------
| 1000| 0|unlck|ena |busy |up |off|off|off|off|off|off| 1656189
| 1001| 0|unlck|ena |busy |up |off|off|off|off|off|off| 1656191
| 1002| 0|unlck|ena |busy |up |off|off|off|off|off|off| 1656189
| 1003| 0|unlck|ena |busy |up |off|off|off|off|off|off| 1656189
| 1200| 0|unlck|ena |busy |up |off|off|off|off|off|off| 886195
| 1300| 0|unlck|ena |busy |up |off|off|off|off|off|off| 568069
ok 2007-11-22 22:45:59.84
Files after parsing:
File1:
1000;unlck;ena;busy;workin;noRequ;protec;noRequ;protec;;2
1001;unlck;ena;busy;workin;noRequ;protec;noRequ;protec;;0
1002;unlck;ena;busy;workin;noRequ;protec;noRequ;protec;;0
1003;unlck;ena;busy;workin;noRequ;protec;noRequ;protec;;0
1200;unlck;ena;busy;workin;noRequ;protec;noRequ;protec;;6
1300;unlck;ena;busy;workin;noRequ;protec;doNotR;protec;;0
ok2007-11-2222:45:58.21
File2:
1000;0;unlck;ena;busy;up;off;off;off;off;off;off;1656189
1001;0;unlck;ena;busy;up;off;off;off;off;off;off;1656191
1002;0;unlck;ena;busy;up;off;off;off;off;off;off;1656189
1003;0;unlck;ena;busy;up;off;off;off;off;off;off;1656189
1200;0;unlck;ena;busy;up;off;off;off;off;off;off;886195
1300;0;unlck;ena;busy;up;off;off;off;off;off;off;568069
ok2007-11-2222:45:59.84
Here is the function, I am loading the file then reading each line.
===============================================
Function FileParser (filenme)
' On Error Resume Next
Dim regExp1 : Set regExp1 = New RegExp
regExp1.Pattern = "(|)?\d+.(|)?"
regExp1.IgnoreCase = True
Set filEtextFile = filesys.GetFile(filenme)
Set testFile = filEtextFile.OpenAsTextStream(ForReading)
Report="" 'the idea to be proper requires reset to empty'
Do Until testFile.AtEndOfStream
varLine = testFile.ReadLine
If (regExp1.Test(varLine)) And (Len(Trim(varLine)) > 5) And (InStr(varLine, ">") = False) Then
If (Left(varLine,1) = "|") Then
Report = Report & Mid(Trim(varLine),2) & vbCrLf
Else
Report = Report & Trim(varLine) & vbCrLf'
End If
End If
Loop
Do While Instr(Report, " ")
Report = Replace(Report, " ", "")
Loop
'Change delimiter
Report = Replace(Report, "|", ";")
''''''''''Write the changed text back to the file
Set testFile = filEtextFile.OpenAsTextStream(ForWriting)
testFile.Write Report
testFile.Close
End Function