I have to basically strip out a block of text from file1. The file1 is huge of many thousand lines (~3GB size). The block looks as below,
line 1
line 2
Your proposal is simple to understand and implement. This also makes it easy to debug, maintain, and update. Yes, this is a good approach to use.
start_pattern_list = # Make this a list of all the patterns from file2
stop_pattern = "}\n"
out_flag == False
for line in <input file>:
if '<' in line:
if any(p in line for p in start_pattern_list):
out_flag = True # Turn on output
if out_flag:
out_file.write(line)
if stop_pattern in line:
out_flag = False # Turn off output
This works for simple files: no nested braces, the input trigger (pattern) appears only as a pattern (not embedded within the braces).