Community
    • Login

    Search and replace with increasing interger

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 3 Posters 307 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G
      goose-ws
      last edited by

      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 of panicExit will have an error code of 1, the second of 2, 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!

      PeterJonesP 1 Reply Last reply Reply Quote 1
      • PeterJonesP
        PeterJones @goose-ws
        last edited by PeterJones

        @goose-ws ,

        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)

        CoisesC 1 Reply Last reply Reply Quote 1
        • G
          goose-ws
          last edited by

          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!

          1 Reply Last reply Reply Quote 1
          • CoisesC
            Coises @PeterJones
            last edited by

            @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.

            PeterJonesP 1 Reply Last reply Reply Quote 1
            • PeterJonesP
              PeterJones @Coises
              last edited by

              @Coises ,

              Fixed. In the future, you could just chat-message the FAQ author (in this case, me).

              1 Reply Last reply Reply Quote 1
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors