多くの行を含むログ ファイルがあります。ログファイルは csv 形式です。そのファイルでさまざまなメッセージを検索しており、それらを別のファイルに保存したいと考えています。
どうすればそれを管理できますか?
現在、私は次のようにしています:
with open('/tmp/result/warnings/test/test3.csv', 'r') as input_file:
with open('/tmp/result/warnings/test/test4.csv', 'w') as output_file:
for line in input_file:
if not "Failed to open output file" in line:
output_file.write(line)
with open('/tmp/result/warnings/test/test4.csv', 'r') as input_file:
with open('/tmp/result/warnings/test/test5.csv', 'w') as output_file:
for line in input_file:
if not "Invalid file length of" in line:
output_file.write(line)
一度に複数のメッセージを検索して、1 つのファイルに書き込むようなことはできますか?