I have a text file that takes the form of:
first thing: content 1
second thing: content 2
third thing: content 3
fourth thing: content 4
This pattern repeats throughout the entire text file. However, sometimes one of the rows is completely gone like so:
first thing: content 1
second thing: content 2
fourth thing: content 4
How could I search the document for these missing rows and just add it back with a value of "NA" or some filler to produce a new text file like this:
# 'third thing' was not there, so re-adding it with NA as content
first thing: content 1
second thing: content 2
third thing: NA
fourth thing: content 4
Current code boilerplate:
with open('original.txt, 'r') as in:
with open('output.txt', 'wb') as out:
#Search file for pattern (Maybe regex?)
#If pattern does not exist, add the line
Thanks for any help you all can offer!
1, 2, 3, 4could really be two blocks:line 1 & 2 with missing 3 & 4plusmissing 1 & 2 followed by line 3 & 4...\nbetween the blocks)