I'm attempting to parse a file whose contents follow this format;
4:/eula.1028.txt:
8:/eula.1031.txt:
19:/eula.1033.txt:
23:/eula.1036.txt:
27:/eula.1040.txt:
31:/eula.1041.txt:
35:/eula.1042.txt:
39:/eula.2052.txt:
43:/eula.3082.txt:
The number of lines of the file will vary but the format is constant; #:TEXT:
What I would like is for the script to subtract the numerical variables of a line (starting with line 1 and 2) from the line above it, -3 then associate that new value with the above TEXT and output the results to a new file. An example of the formula I have in mind would be expressed something like this;
Line #2 = 8
Line #1 = 4
So; (8 - 4) = 4 - 3 = 1
THEN
Line #3 = 19
Line #2 = 8
So; (19 - 8) = 11 - 3 = 8
And so on until it reaches the end of the file.
For example, the results of the new file should look like this;
1:/eula.1028.txt:
8:/eula.1031.txt:
1:/eula.1033.txt:
1:/eula.1036.txt:
1:/eula.1040.txt:
1:/eula.1041.txt:
1:/eula.1042.txt:
1:/eula.2052.txt:
Line 43:/eula.3082.txt: would not be able to be figured as there is no following line to subtract from and the script should end.
I've been attempting to utilize bash, awk, sed, to get this done but it's just eluding me. I'm not a perl programmer at all but I suspect there is likely a simple way to perform this function in perl, but in bash I keep chasing my tail.
Thanks in advance for any help on this one!