Answer to
# version 3
import re
def main():
file_one = 'file-1.txt'
file_two = 'file-2.txt'
word_tuples = []
with open(file_one, 'r') as file:
for line in file:
words = line.split() # splits on white space
word_tuples.append((words[0], words[1]))
new_lines = []
with open(file_two, 'r') as file:
for line in file:
# Look for StaticMesh lines
match = re.search(r"StaticMesh=?'(.+)'", line)
if not match:
new_lines.append(line.strip())
continue
quoted_word = match.group(1)
# see if any of the lines from file 1 match it
was_found = False
for word_tuple in word_tuples:
if word_tuple[0] == quoted_word:
new_lines.append(line.replace(quoted_word, word_tuple[1]))
was_found = True
if not was_found:
new_lines.append(line.strip())
for new_line in new_lines:
print(new_line)
if __name__ == '__main__':
main()
Run this as :
python3 main.py