我当前的脚本正在运行(请参见下文),但单行匹配。如何匹配多行?
for filename in os.listdir(path):
with open(os.path.join(path,filename), "r") as infile:
check1 = "fail"
check2 = "fail"
for line in infile:
if line.startswith("logging buffered 16384"):
check1 = 'pass'
if line.startswith("logging console informational"):
check2 = 'pass'
fh.write("{},{},{}\n".format(filename, check1, check2))
fh.close()
答案 0 :(得分:0)
如果result
中的所有项目都在checks
file
的值为True。
checks = ["line1", "line2"]
file = ["line3", "line4", line5", "line1", "line2"]
result = (all([True for line in checks if line in file]))
将要搜索的行定义为列表,然后在文件上运行以上代码。