Search and replace with increasing interger
-
In a script I’m working on, I account for unexpected outcomes with a line:
panicExit "1" "Some error message goes here"
Where
panicExit
is the exit function,"1"
is the error code, and"Some error message goes here"
is the error message.Over the length of this script, as I’m writing my logic statements, I end up with a lot of these
panicExit
lines. They are always the only thing in whatever line number they are found on, but they may have any number of leading spaces or tabs. What I would like to do is search/iterate through every line of the file, and if we find the pattern:panicExit "[[:digit:]]+" ".*"
Replace that
[[:digit:]]+
with an auto-increasing number. So the first instance ofpanicExit
will have an error code of1
, the second of2
, and so on.I’m not sure if the built-in “Macro” function is capable of this or not. I’d appreciate any direction on the best way to accomplish this. Thanks!
-
Sounds like a job for the Columns++ plugin – the “replace with a counter” example is shown in our Mathematical Replacement FAQ (in an earlier section of the FAQ, it explains how to do the same thing in PythonScript plugin; or you can use the
CNT
variable in the Multi Replace plugin, described later in the FAQ) -
Thanks for the quick reply and suggestion! I don’t have enough rep to upvote, so please accept this response as gratitude instead. Appreciate your time!
-
@PeterJones said in Search and replace with increasing interger:
Columns++ plugin […] in our Mathematical Replacement FAQ
I’m not sure where FAQ corrections should go, but I just noticed the FAQ says Columns++ is not available through Plugins Admin, which is no longer true.
-
@Coises ,
Fixed. In the future, you could just chat-message the FAQ author (in this case, me).