Какой размер файла журнала?Ряды?и Kb / Mb / Gb?
VBA выше делает Readall, затем Split, затем Loop / Cells, чтобы получить все это в Excel
Эта новая процедура читает каждую строку и ищет 5 запрошенныхполя, сохраняя их в локальные переменные.При достижении «Info:» он получает данные Com10, а затем записывает новую строку в вывод.Всякий раз, когда Mode_Name или Cond_Id неверны, он обходит все строки до следующего "%%%".
Sub doLogFile()
' Get filename of input
Dim fPathOfInput As String
With Application.FileDialog(msoFileDialogFilePicker)
If .Show = 0 Then
fPathOfInput = ""
Else
fPathOfInput = .SelectedItems(1)
End If
End With
If Right(fPathOfInput, 4) <> ".txt" _
Or fPathOfInput = "" Then
MsgBox ("No input txt file selected. fn=" & fPathOfInput)
Exit Sub
End If
' Create new XLS with modified FN, with column heads
Dim wbOutput As Workbook, wsOutput As Worksheet, fPathOfOutput As String, nRow As Long
Const wsMySheetName As String = "FoundRows"
Set wbOutput = Workbooks.Add
wbOutput.ActiveSheet.Name = wsMySheetName
Set wsOutput = wbOutput.ActiveSheet
fPathOfOutput = Replace(fPathOfInput, ".txt", ".xlsx")
wbOutput.SaveAs Filename:=fPathOfOutput
nRow = 1
wsOutput.Cells(nRow, 1) = "Cond_Id"
wsOutput.Cells(nRow, 2) = "Mode_Name"
wsOutput.Cells(nRow, 3) = "Exec_time"
wsOutput.Cells(nRow, 4) = "Com10 -Sub_Task"
wsOutput.Cells(nRow, 5) = "Com10 -Com_Task"
wsOutput.Cells(nRow, 6) = "LineNumber"
' Open file, Read Each Row, Process, Close file
Dim textLine As String, cntLines As Long
cntLines = 0
Open fPathOfInput For Input As #1
Do Until EOF(1)
Line Input #1, textLine
cntLines = cntLines + 1
' Process each Row
Dim sLookFor As String
Dim posExecTime As Integer, saveExecTime As String
Dim saveModeName As String
Dim saveCondId As String, rowCondId As Long
Dim posCom10 As Integer, posCom11 As Integer, txtCom10 As String, saveSubTask As String, saveComTask As String
If Left(textLine, 3) = "%%%" Then
sLookFor = "A"
rowCondId = 0
saveExecTime = "": saveModeName = "": saveCondId = "": saveSubTask = "": saveComTask = ""
End If
If sLookFor <> "X" Then
posExecTime = InStr(textLine, "Exec_time")
If posExecTime Then
saveExecTime = Mid(textLine, posExecTime)
GoTo gotoLoop
End If
If Mid(textLine, 1, 10) = "Mode_Name:" Then
saveModeName = Mid(textLine, 12)
'If saveModeName = "Mode1_xx_ALA" Then
If Left(saveModeName, 6) = "Mode1_" And Right(saveModeName, 5) = "_ALA;" Then
Else
sLookFor = "X"
End If
GoTo gotoLoop
End If
If Mid(textLine, 1, 13) = "Condition_Id:" Then
saveCondId = Mid(textLine, 15)
If saveCondId = "X-MODE1-999999I;" Then
'If Left(saveCondId, 6) = "zzzz" And Right(saveCondId, 4) = "zzz" Then
rowCondId = cntLines
Else
sLookFor = "X"
End If
GoTo gotoLoop
End If
If Mid(textLine, 1, 5) = "Info:" Then
' Find Com10
posCom10 = InStr(textLine, "Com10:")
posCom11 = InStr(textLine, "Com11:")
Dim posSubTask As Integer, posComTask As Integer, posSemi As Integer
If posCom10 And posCom11 Then
txtCom10 = Mid(textLine, posCom10 + 7, posCom11 - posCom10 - 7)
' got -- Sub_Task: NNNN; Com_Task: NNNN;;
posSubTask = InStr(txtCom10, "Sub_Task:")
posSemi = InStr(txtCom10, ";")
saveSubTask = Mid(txtCom10, posSubTask + 10, posSemi - posSubTask - 10)
posComTask = InStr(posSemi, txtCom10, "Com_Task:")
posSemi = InStr(posSemi + 1, txtCom10, ";")
saveComTask = Mid(txtCom10, posComTask + 10, posSemi - posComTask - 10)
' Write Excel row
nRow = nRow + 1
wsOutput.Cells(nRow, 1) = saveCondId
wsOutput.Cells(nRow, 2) = saveModeName
wsOutput.Cells(nRow, 3) = saveExecTime
wsOutput.Cells(nRow, 4) = saveSubTask
wsOutput.Cells(nRow, 5) = saveComTask
wsOutput.Cells(nRow, 6) = rowCondId
End If
' Turn off scan
sLookFor = "X"
GoTo gotoLoop
End If
End If
gotoLoop:
Loop
Close #1
nRow = nRow + 1
wsOutput.Cells(nRow, 1) = "Total Rows in text file"
wsOutput.Cells(nRow, 6) = cntLines
End Sub