Try this:
def reformat():
product = {}
f = open('inputfile.txt', 'r')
for line in f:
line = line.rstrip('\n')
if line.startswith('product'):
prod = line.split()
for field in prod[1:]:
key, value = field.split('=')
product[key] = value
elif line.startswith('sys_name'):
key, value = line.split('=')
product[key] = value
else:
if len(product) > 0:
print('product', end=' ')
if 'control_type' in product:
for key in [ 'name', 'sys_name', 'control_type' ]:
print(F'{key}={product[key]}', end = ' ')
else:
for key in [ 'name', 'sys_name', 'act_ferq', 's_c' ]:
print(F'{key}={product[key]}', end = ' ')
print('')
product = {}
print(line)
This is a quick and dirty solution and can be cleaned up in a few areas. Obviously the print statements need to be changed to write to the output file.