@SilentBronyRain said in insert increasing number before/after specified word:
I need to insert a number every time selected word appears in the document.
As well as a scripting option it can also be achieved with regular expressions and other built-in functions:
Insert line number at the beginning of each line Mark (bookmark) each line with the word Polka in it Cut the marked lines and paste into another tab Insert an increasing number at the end of each line (this can start at 0) move the just inserted line number (step #4) to the position behind the word Polka Cut/Copy these lines back into the original file, at end Sort the lines by using the line number inserted step #1 Remove the line numbersI deliberately haven’t provided the actual commands, I will leave that for the OP to figure out. They aren’t difficult and could be a worthwhile learning experience. When inserting numbers in step #1 it’s important to tick the box “leading zeros” as otherwise sorting will not put the lines back into the original order.
Note this works when only 1 “key word” is on each line. It would be possible to re-work the above process with multiple key words on each line but that would be a complicated exercise.
Terry