Archive: Line replacement with number shifting


Line replacement with number shifting
Hello,

I have a 1500 lines text file with 300 lines with only the string "[n]" where n is a number that change from 0 to 299.

Currently in the file there are 252 lines from [0] to [251] and now I would change the range from '[21]' to '[251]' into the range from '[69]' to '[299]', then to shift the numbers, within the line, by 48.

I have written the following code but it does not work:

...

Section
${LineFind} "input.txt" "output.txt" "1:-1" "Replace"
SectionEnd

Function Replace
StrCpy $R0 251 ; begin item
StrCpy $R1 21 ; end item
StrCpy $R2 48 ; replacement offset
${ForEach} $R3 $R0 $R1 - 1
IntOp $1 $R3 + $R2
${WordReplace} "$R9" $R3 $1 "" $R9
${Next}
Push $0
FunctionEnd

...

Can you give me the right code (I think for the 'Replace' function') ?


Could you describe exactly what doesn't work with your code and provide an example file showing the structure?


Hello, thanks for the reply

in the while I have found by myself the working code. It has simply a better definition for WordReplace; it is:

...

Section
${LineFind} "input.txt" "output.txt" "1:-1" "Replace"
SectionEnd

Function Replace
StrCpy $R0 251 ; begin item
StrCpy $R1 21 ; end item
StrCpy $R2 48 ; replacement offset
${ForEach} $R3 $R0 $R1 - 1
IntOp $1 $R3 + $R2
${WordReplace} "$R9" "[$R3]" "[$1]" "+1" $R9
${Next}
Push $0
FunctionEnd