With "data.dat" as your file:
with open("data.dat", "r") as msg:
data = msg.readlines()
output = 0
for line in data:
with open(str(output)+"_data.dat", "w") as msg:
for i, char in enumerate(line.strip().split()):
msg.write("x%s %s %s*2
" % (str(i+1),char,char))
output += 1
You read your file in a list, you read the lines one by one, you write a new file each line. You split your line and build your string to write in the file.