Community
    • Login

    Need help with replacing all lines matching a number and replacing those numbers every odd/even interval

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 584 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.
    • A
      AzurBarnitzke
      last edited by

      So I have a .json file formatted like this

      {
                  "cumulated": 448,
                  "delay": 0,
                  "download": true,
                  "filenameOverride": "",
                  "getBlacklisted": false,
                  "interval": 1200,
                  "lastCheck": "2022-01-05T16:55:07Z",
                  "lastState": {
                      "count": 4,
                      "since": "2022-01-05T14:55:49Z",
                      "state": "finished"
                  },
                  "notify": true,
                  "pathOverride": "",
                  "postFilters": [
                  ],
                  "preciseCumulated": true,
                  "query": {
                      "tags": [
                          "filter:images",
                          "wxyz"
                      ]
                  },
                  "sites": [
                      "google.com"
                  ]
              },
              {
                  "cumulated": 97,
                  "delay": 0,
                  "download": true,
                  "filenameOverride": "",
                  "getBlacklisted": false,
                  "interval": 1200,
                  "lastCheck": "2022-01-05T16:55:09Z",
                  "lastState": {
                      "count": 62,
                      "since": "2022-01-04T08:35:28Z",
                      "state": "finished"
                  },
                  "notify": true,
                  "pathOverride": "",
                  "postFilters": [
                  ],
                  "preciseCumulated": true,
                  "query": {
                      "tags": [
                          "filter:images",
                          "qwerty"
                      ]
                  },
                  "sites": [
                      "google.com"
                  ]
              },
              {
                  "cumulated": 47,
                  "delay": 0,
                  "download": true,
                  "filenameOverride": "",
                  "getBlacklisted": false,
                  "interval": 1200,
                  "lastCheck": "2022-01-05T16:55:10Z",
                  "lastState": {
                      "count": 621,
                      "since": "2021-12-26T03:31:30Z",
                      "state": "finished"
                  },
                  "notify": true,
                  "pathOverride": "",
                  "postFilters": [
                  ],
                  "preciseCumulated": true,
                  "query": {
                      "tags": [
                          "filter:images",
                          "wasd"
                      ]
                  },
                  "sites": [
                      "google.com"
                  ]
              },
      

      I want to replace the first occurrence of “interval”: 1200, to “interval”: 1200, then the next occurrence of “interval”: 1200, with “interval”: 2100, till the end of the text document, sort of like creating every odd occurrence with an interval of 1200 and the even occurrences with 2100 any way how I can possibly achieve this?

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

        @azurbarnitzke ,

        In native Notepad++ search/replace regular expressions – there is no “counter”, as such, in regular expressions.

        If you are willing to use the PythonScript plugin and write a simple script, then it’s easier – search for add_1 in the forum, and you’ll have plenty of examples of doing math on a number.

        But actually, since you only have two sets of replacements, it might be doable in regular expressions, depending on how many characters are between the odd interval and the even interval.

        If I have the data

        prelim
        "interval": 1200,
        other: stuff,
        other: stuff,
        "interval": 1200,
        other: stuff,
        other: stuff,
        "interval": 1200,
        other: stuff,
        other: stuff,
        "interval": 1200,
        other: stuff,
        other: stuff,
        

        then if the cursor is at the top of the page,
        FIND = (?s)"interval": 1200,.*?\K"interval": 1200,
        REPLACE = "interval": 2100,
        MODE = regular expression
        REPLACE ALL
        it will become

        prelim
        "interval": 1200,
        other: stuff,
        other: stuff,
        "interval": 2100,
        other: stuff,
        other: stuff,
        "interval": 1200,
        other: stuff,
        other: stuff,
        "interval": 2100,
        other: stuff,
        other: stuff,
        

        … which I think is what you want.

        In the regex manual, especially study \K

        ----

        Useful References

        • Please Read Before Posting
        • Template for Search/Replace Questions
        • FAQ: Where to find regular expressions (regex) documentation
        • Notepad++ Online User Manual: Searching/Regex
        A 1 Reply Last reply Reply Quote 2
        • A
          AzurBarnitzke @PeterJones
          last edited by

          @peterjones Thanks a lot! did the job better

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