I have a text file with lines formatted like this:
FC|100abc|100,0.1517:150,0.06632:250,0.03562:750,0.017888:1250,0.010292:2500,0.006426:5000,0.005385:15000,0.0033428:25000,0.0026424:50000,0.0021614:0,0.0021399|
...and so-on. You can see that the line has three 'elements', enclosed by '|' characters (well, sort of: I know there's no '|' character at the beginning of the line, but otherwise you can see the 'elements' I'm identifying here). The first 'element' of the line above is "FC", the second 'element' is "100abc", and the third is the long string "100,0.1517:[...etc...]:0,0.0021399".
A script I'm writing takes data from this file successfully. But I want to do some more interrogation of this file, and I can't work it out. I want to search each line like the one above, and:
- Pull out every pair of the third element that's separated by a colon and divided by a comma, and put these into two columns, like:
100/0.1517
150/0.06632
250/0.03562
750/0.017888
[etc]
- Work down the resultant left-hand column at (1) above (ie, 100, 150, 250, 750, etc), summing these values of the left-hand column (100+150+250+750 etc), and when the summation is equal to or greater than a predefined integer variable (eg, $PE, with, say, a value of 500), to return the corresponding right-hand column figure.
With my example $PE value of 500, a value of 0.03562 would be returned (because 100+150+250 is equal to 500). With a $PE value of 249, the value of 0.06632 would be returned (because 100+150 is larger than 250).
Any help appreciated!