in reply to nmr comparison script

Whoa. There is so much about your post that is incomprehensible (and so much of it) that it's hard to figure out where to start. I'll try an unordered list...

There are some "stylistic issues" too, but no point going into that, given the issues above.

So how about you start over with first principles: you've given a sample of one of the "original" input files, so how about you give (a) a sample of the other input, (b) the intended output, and (c) a brief summary of the criteria and relations that cause the output to be what it is. Think of that summary in terms of a synopsis or a minimal recipe -- that is, think about how you would document this process, how you would provide an overview of what the program is supposed to do. (My rule: write the docs/specs first, well enough that someone else can understand them, before writing any code.)

Forget about the code you've posted -- it's entirely wrong and it should be deleted. Write the concise description of what your process must do in terms of the input, the output and the logic that relates these two. Then start writing the code from scratch to address that description (or start a new SoPW thread with a question about how to approach that task).