Replace line of text with another line of text from another file. Given a text file (file.txt):
cat `macro` is cool
dog `gas` is cool
Associated substitute for macro (macro.txt):
macro:jason
gas:super
to make:
cat jason is cool
dog super is cool
I was thinking along the lines of find and replace, however, my case requires many macro substitutes from the list. Everything is in a text file.
with open('file.txt',r) as A:
with open('macro.txt',r) as B:
macro=A.read()
text=B.read()
for l in text:
for i in macro:
if i=l:
A=A.replace(i,l)