I am using this code for searching a target_string in a single input file (input.txt) and "extracting" those lines with the target_string in an output file (output.txt). Now I want to perform the same procedure but with several input files, for instance, input1.txt, input2.txt, input3.txt, ...
How can I modify this code for doing this?
from collections import deque
input_file = 'input.txt'
output_file = 'output11.txt'
buscado = 'TCGCCATCCGAATTCCA'
contexto = deque([], 4) # for keeping the last 4 lines
with open(input_file) as f_in, open(output_file, "w") as f_out:
# Un bucle for que itere por `f_in` recuperará una línea de cada vez
for line in f_in:
contexto.append(line)
if len(contexto) < 4:
continue
if buscado in contexto[1]:
f_out.writelines(contexto)
Does anyone has any suggestion? I've been struggling for hours :C