以下是关于我的文件的概述:
[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'
我如何确保将所有包含“Window”文本的行都写入新文件中?谢谢您提前的回答,Valentine。
eachline
,它可以减少你需要编写的代码行数。 - Fredrik Bagge