Community
    • Login

    Find and increment by 1

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 3 Posters 3.1k 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.
    • Saima RafiqS
      Saima Rafiq
      last edited by

      Hi ;

      I have multiple hits of number 45371001190000 in the text document so for each hit i want to increase the number by 1 for example for first hit no change to 45371001190000 for 2nd hit it should be updated to 45371001190001 and for the next 45371001190002 and so on .

      Thanks to advance for the help,

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Saima Rafiq
        last edited by

        @Saima-Rafiq

        You need a programming language to help with this, I’m afraid. You could certainly use a scripting plugin for Notepad++ as that programming language…

        Saima RafiqS 1 Reply Last reply Reply Quote 1
        • Saima RafiqS
          Saima Rafiq @Alan Kilborn
          last edited by

          @Alan-Kilborn I can add the script plugin to Notepad++ , can you help with the script which can get me the desire result ?

          Alan KilbornA 1 Reply Last reply Reply Quote 0
          • Alan KilbornA
            Alan Kilborn @Saima Rafiq
            last edited by Alan Kilborn

            @Saima-Rafiq

            Sure. There’s already a great example for Pythonscript that is close to what you want to do:

            In the help file for editor.rereplace:

            def add_1(m):
                return 'Y' + str(number(m.group(1)) + 1)
            
            # replace X followed by numbers by an incremented number
            # e.g.   X56 X39 X999
            #          becomes
            #        Y57 Y40 Y1000
            
            editor.rereplace('X([0-9]+)', add_1);```
            1 Reply Last reply Reply Quote 3
            • guy038G
              guy038
              last edited by

              Hello, @saima-rafiq, @Alan-kilborn and All,

              Of course this short Python script is ridiculously easy to understand ;-))

              With regular expressions, it’s a little longer but still doable !


              For instance, given the sample text :

              The number 45371001190000 is increasing...
              The number 45371001190000 is increasing...
              The number 45371001190000 is increasing...
              The number 45371001190000 is increasing...
              The number 45371001190000 is increasing...
              The number 45371001190000 is increasing...
              The number 45371001190000 is increasing...
              The number 45371001190000 is increasing...
              The number 45371001190000 is increasing...
              The number 45371001190000 is increasing...
              The number 45371001190000 is increasing...
              The number 45371001190000 is increasing...
              The number 45371001190000 is increasing...
              The number 45371001190000 is increasing...
              The number 45371001190000 is increasing...
              The number 45371001190000 is increasing...
              The number 45371001190000 is increasing...
              The number 45371001190000 is increasing...
              The number 45371001190000 is increasing...
              The number 45371001190000 is increasing...
              
              • With this fist regex S/R, we add the left part of the number, at beginning of lines, followed with a space character :

                • SEARCH ^

                • REPLACE 4537100\x20

              giving :

              4537100 The number 45371001190000 is increasing...
              4537100 The number 45371001190000 is increasing...
              4537100 The number 45371001190000 is increasing...
              4537100 The number 45371001190000 is increasing...
              4537100 The number 45371001190000 is increasing...
              4537100 The number 45371001190000 is increasing...
              4537100 The number 45371001190000 is increasing...
              4537100 The number 45371001190000 is increasing...
              4537100 The number 45371001190000 is increasing...
              4537100 The number 45371001190000 is increasing...
              4537100 The number 45371001190000 is increasing...
              4537100 The number 45371001190000 is increasing...
              4537100 The number 45371001190000 is increasing...
              4537100 The number 45371001190000 is increasing...
              4537100 The number 45371001190000 is increasing...
              4537100 The number 45371001190000 is increasing...
              4537100 The number 45371001190000 is increasing...
              4537100 The number 45371001190000 is increasing...
              4537100 The number 45371001190000 is increasing...
              4537100 The number 45371001190000 is increasing...
              
              • Now, place the caret, on the 1st line, right after the number 4537100

              • Select the option Edit > Column Editor... ( Alt + C )

              • Choose the option Number to Insert

              • Type in 1190000 in field Initial number

              • Type in 1 in field Increase by

              • Type in 1 in field Repeat

              • Select, if necessary, the Dec format

              • Click on the OK button

              We get :

              45371001190000 The number 45371001190000 is increasing...
              45371001190001 The number 45371001190000 is increasing...
              45371001190002 The number 45371001190000 is increasing...
              45371001190003 The number 45371001190000 is increasing...
              45371001190004 The number 45371001190000 is increasing...
              45371001190005 The number 45371001190000 is increasing...
              45371001190006 The number 45371001190000 is increasing...
              45371001190007 The number 45371001190000 is increasing...
              45371001190008 The number 45371001190000 is increasing...
              45371001190009 The number 45371001190000 is increasing...
              45371001190010 The number 45371001190000 is increasing...
              45371001190011 The number 45371001190000 is increasing...
              45371001190012 The number 45371001190000 is increasing...
              45371001190013 The number 45371001190000 is increasing...
              45371001190014 The number 45371001190000 is increasing...
              45371001190015 The number 45371001190000 is increasing...
              45371001190016 The number 45371001190000 is increasing...
              45371001190017 The number 45371001190000 is increasing...
              45371001190018 The number 45371001190000 is increasing...
              45371001190019 The number 45371001190000 is increasing...
              
              • Finally, the regex S/R, below, overwrites the 45371001190000 number with the increasing number, at present start of lines

                • SEARCH (?-s)^(\d+)(.+?)45371001190000

                • REPLACE \2\1

               The number 45371001190000 is increasing...
               The number 45371001190001 is increasing...
               The number 45371001190002 is increasing...
               The number 45371001190003 is increasing...
               The number 45371001190004 is increasing...
               The number 45371001190005 is increasing...
               The number 45371001190006 is increasing...
               The number 45371001190007 is increasing...
               The number 45371001190008 is increasing...
               The number 45371001190009 is increasing...
               The number 45371001190010 is increasing...
               The number 45371001190011 is increasing...
               The number 45371001190012 is increasing...
               The number 45371001190013 is increasing...
               The number 45371001190014 is increasing...
               The number 45371001190015 is increasing...
               The number 45371001190016 is increasing...
               The number 45371001190017 is increasing...
               The number 45371001190018 is increasing...
               The number 45371001190019 is increasing...
              

              Of course, just an exercise…, ah ah !


              But I just realize that, in case the 45371001190000 number is not on consecutive lines, the Column Editor method does not work. Indeed, the script method is the definitive one ;-))

              Best Regards

              guy038

              Alan KilbornA 1 Reply Last reply Reply Quote 0
              • Alan KilbornA
                Alan Kilborn @guy038
                last edited by

                @guy038 said in Find and increment by 1:

                But I just realize that, in case the 45371001190000 number is not on consecutive lines

                I’m glad you realized that…

                :-)

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