【发布时间】:2023-03-14 21:33:01
【问题描述】:
这是我的文件的概述:
[2020/06/18 17:19:25] Window closed --> OptionDialog = 'Waiting Dialog - Session restore' --> frame = 'DataManager'
[2020/06/18 17:19:40] Window opened --> frame = 'DataManager'
[2020/06/18 17:19:40] MB1 --> Menu item = [Toolbox] --> frame = 'DataManager'
[2020/06/18 17:19:42] MB1 --> Menu item = [2G&R Synthesis toolbox, Toolbox] --> Popup Menu --> frame = 'DataManager'
[2020/06/18 17:19:42] Window opened --> frame = 'ToolBox'
[2020/06/18 17:19:42] Window gained focus --> frame = 'ToolBox'
我想只检索日期之后带有子字符串“Window”的行,然后将它们写入一个新的文本文件。 这是我到目前为止所做的:
file = open("Test2.txt") do file
f = readlines(file)
for line in f
if line[23:28]== "Window"
open("t.txt","w") do file
write(file,line)
end
end
end
end
我的问题是只有第一个文件中包含“Window”的最后一行被写入新文件。 例如这里是:
[2020/06/18 17:19:42] Window gained focus --> frame = 'ToolBox'
如何确保ALL包含“Window”的行被写入新文件?
提前感谢您的回答,
情人节
【问题讨论】:
-
看看函数
eachline,它将减少您需要的代码量。 -
我只是在写这个:)。并同意 - 这是一种首选方式,因为它不必将整个文件读入内存。