Ну, тут ещё можно продолжить мудрить, когда позиции не совпадают, но идут по порядку, а пока рабочий вариант для совпадающих позиций:
import re
PATTERN_IN = '1'
#use this, if it is needed
#PATTERN_OUT = '=LDR.*'
FILE_SOURCE = 'slkmarc.dat'
FILE_REPLACER = 'ukmarc.mrk'
FILE_OUT = 'output.txt'
with open(FILE_SOURCE) as f:
lines_source = f.readlines()
with open(FILE_REPLACER) as f:
lines_replacer = f.readlines()
def replace_by_position(lines_source, lines_replacer):
"""
works only when line numbers are same for both files
"""
for index, line in enumerate(lines_source):
if re.match(PATTERN_IN, line.strip()):
if index < len(lines_replacer):
lines_source[index] = lines_replacer[index]
else:
break
replace_by_position(lines_source, lines_replacer)
with open(FILE_OUT, 'w') as f:
f.writelines(lines_source)