我有一个非常大的文件需要解析。我不需要任何高达'&'
. 我只需要'&'
文件中的信息。如何删除之前的行'&'
?这是我到目前为止所拥有的:
import re
original_file = 'file.rpt'
file_copy = 'file_copy.rpt'
with open(original_file, 'r') as rf:
with open(file_copy, 'r+') as wf:
for line in rf:
#if statement to write after the '&' has been encountered?
wf.write(line)
输入文件:
sample text1
sample text2
sample text3
sample text4
&sample text5
sample text6
expected output file:
&sample text5
sample text6
在 rpt 文件中,它有 6 行,第 1-4 行是不需要的信息。我想删除第 1-4 行,所以我可以专注于第 5 和第 6 行。