I have a txt file named "tclust.txt" and another named "ef_blue.txt." I'm trying to write a python script which will allow me to import certain characters from ef_blue.txt to tclust.txt. So far, I can only read in the values from ef_blue.txt and have everything from that txt file go to tclust.txt. My ef_blue.txt has multiple lines of text but I only want to take certain characters from each line (e.g.: "7.827382" from line 2 and "6.432342" from line 2.
blue = open("ef_blue.xpk", "rt")
contents = blue.read()
with open("tclust.txt","a") as f2:
f2.writelines(contents)
blue.close()
f2.close()
Edit: My tclust.txt file looks like this:
"type rbclust
Peak 0 8.5 0.05 4.0 0.05
Atom 0 125.H8 126.H1' label dataset sw sf"
My ef_blue.xpk file looks like this:
"label dataset sw sf
1H 1H_2
NOESY_F1eF2f.nv
4807.69238281 4803.07373047
600.402832031 600.402832031
1H.L 1H.P 1H.W 1H.B 1H.E 1H.J 1H.U 1H_2.L 1H_2.P 1H_2.W 1H_2.B 1H_2.E 1H_2.J 1H_2.U vol int stat comment flag0 flag8 flag9
0 {} 7.45766 0.01702 0.03286 ++ {0.0} {} {} 5.68094 0.07678 0.15049 ++ {0.0} {} 0.0 4.8459 0 {} 0 0 0
1 {} 8.11276 0.02278 0.03212 ++ {0.0} {} {} 5.52142 0.07827 0.11252 ++ {0.0} {} 0.0 2.0824 0 {} 0 0 0
2 {} 7.85285 0.02369 0.02232 ++ {0.0} {} {} 5.52444 0.07280 0.06773 ++ {0.0} {} 0.0 0.8844 0 {} 0 0 0
3 {} 7.45819 0.01630 0.02914 ++ {0.0} {} {} 5.42587 0.07081 0.11733 ++ {0.0} {} 0.0 2.8708 0 {} 0 0 0
4 {} 7.89775 0.01106 0.00074 ++ {0.0} {} {} 5.23989 0.07077 0.00226 ++ {0.0} {} 0.0 0.4846 0 {} 0 0 0
5 {} 7.85335 0.02665 0.03635 ++ {0.0} {} {} 5.23688 0.09117 0.12591 ++ {0.0} {} 0.0 1.5210 0 {} 0 0 0"
So what I want to do is take the characters from my ef_blue.xpk such as "7.45766" and "5.68094" from line 7 and write it out to line 3 of my tclust.txt file
So I would like my tclust.txt file to look like:
type rbclust Peak 0 8.5 0.05 4.0 0.05 7.45766 5.68094 8.11276 5.52142 .... etc Atom 0 125.H8 126.H1'label dataset sw sf
Edit2: @open-source