#(??01???03)
ld r koha t03 %type lshutter fst
ld l his t01 %type lshutter fst
ld r koha t03 at right %type lshutter fst
ld l his t01 %type lshutter fst
import math
with open('file.txt', 'r+', encoding='utf-8') as file:
data = file.read()
for line in data.splitlines():
if line.startswith('ld r'):
splited = line.split()
midpoint = math.ceil(len(splited) / 2)
splited.insert(midpoint, 'at right')
new_line = ' '.join(splited)
data = data.replace(line, new_line)
file.seek(0)
file.write(data)
file.truncate()