Hopefully a simple script, bash or perl...

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!

awk will do this with two pass through the file.
In 1st pass, just store 1st field (FS=: )in array i.e. a[NR]=$1
In 2nd pass, just apply the formula as below: $1=a[FNR+1]-a[FNR]-3

Thanks for the quick reply!

I've attempted to implement the awk command with the code suggestions you mention but I keep getting a syntax error, probably my clueless ability at coding, I assume this can't be done from the command line?

Can you show me an explicit sinp of the syntax used to perform multiple passes on the file with awk?

Thanks a ton for the help!

---------- Post updated at 03:33 PM ---------- Previous update was at 03:25 PM ----------

I took your answer litterally as you can see here;

#cat input.file | awk -FS: a[NR]=$1 | awk $1=a[FNR+1]-a[FNR]-3 > Result.txt
awk: cmd. line:1: a[NR]=
awk: cmd. line:1:       ^ unexpected newline or end of string
awk: =a[FNR+1]-a[FNR]-3
awk: ^ syntax error

I'm sure this is just me being a doofus.

awk -F: 'NR>1{print ($1-a[1])-3,a[2],X}{split($0,a,":")}' OFS=: infile

Works perfectly! Thank you!!!