我有一个包含超过100,000行数据的日志文件,而且我实际关心的只有大约5000行。其余的大部分都是垃圾,就像下面的情况一样。它在Excel中导入所有~100K行,我无法对任何内容进行分隔。我唯一能做的就是搜索所有" M-SEL"并将其更改为"; M-SEL" (与SAC系列相同)然后开始给我一些划分和解决问题的东西。有没有比我上面列出的更优雅的解决方案(VBA或过滤技术?)?
00:00:00 M-SEL 802151 - - - is supergroup
00:00:01 SAC REJECT - - - 800508 508 is not a valid group id
答案 0 :(得分:1)
您可以使用此宏在多个空格的基础上拆分列:
Sub importLog()
Dim record As String, i As Long, sh As Worksheet, len1 As Long, len2 As Long, ar
Set sh = Worksheets.Add
Open "C:\SO\mylog.txt" For Input As #1 ' <-- Enter your file's name here
Do Until EOF(1)
Line Input #1, record
Do
len1 = Len(record)
record = Replace(record, " ", " ")
len2 = Len(record)
Loop Until len2 = len1
If len1 > 1 Then
i = i + 1
ar = Split(record, " ")
sh.Cells(i, 1).Resize(1, UBound(ar) + 1).value = ar
End If
Loop
Close #1
End Sub