I have a filename with thousands of lines of data in it. I am reading in the filename and editing it.
The following tag is about ~900 lines in or more (it varies per file):
<Report name="test" xmlns:cm="http://www.example.org/cm">
I need to remove that line and everything before it in several files. so I need to the code to search for that tag and delete it and everything above it it will not always be 900 lines down, it will vary; however, the tag will always be the same.
I already have the code to read in the lines and write to a file. I just need the logic behind finding that line and removing it and everything before it.
I tried reading the file in line by line and then writing to a new file once it hits on that string, but the logic is incorrect:
readFile = open(firstFile)
lines = readFile.readlines()
readFile.close()
w = open('test','w')
for item in lines:
if (item == "<Report name="test" xmlns:cm="http://www.example.org/cm">"):
w.writelines(item)
w.close()
In addition, the exact string will not be the same in each file. The value "test" will be different. I perhaps need to check for the tag name ""<Report name"