Hi guys,
First post so please don't be too harsh :D.
I'm trying to open a .txt file, search for a specific line starting with (" Performance Summary"), copying the first and third numbers in the columns of the 4th line below it and every line below that until there is a space.
Here is an example of the txt file, I need the 1st column and 3rd. (It doesn't look like it, but each number has a space e.g. 1000.0 3.86 36.90... and i need the first and third number of each row)
Rubbish
Rubbish
etc.Performance Summary
-------------------
Eng.Speed [rev/min] B.Power [kW] B.Torque [Nm] BMEP [bar] BSFC [g/kW/hr]
-------------------------------------------------------------------------------
1000.0 3.86 36.90 7.74 273.51
2000.0 9.17 43.79 9.18 253.08
3000.0 15.48 49.28 10.33 250.95
4000.0 20.51 48.96 10.26 248.44
5000.0 26.60 50.80 10.65 248.71
6000.0 35.72 56.85 11.92 247.68
7000.0 44.67 60.94 12.78 248.26
8000.0 55.96 66.79 14.00 253.12
Here is what I have so far,I kind of understand that I can join multiple things to the buffer, but I can't get further than copying " Performance Summary" to my output...
data_file = open("file1.txt")
out_file = open("summary.txt", "w")
buffer = []
for line in data_file:
buffer.append(line)
if line.startswith(" Performance Summary"):
out_file.write("".join(buffer))
buffer = []
data_file.close()
out_file.close()
Hope you can help,
Thanks,
Kitson