Community
    • Login

    adding incrementing numbers at the end of each line

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    7 Posts 3 Posters 2.3k 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.
    • Rana JawadR
      Rana Jawad
      last edited by

      so i have a file like this.
      1111111111:
      2222222222:
      3333333333:
      4444444444:
      5555555555:
      i want to put incrementing numbers from 10 to 20 at the end of each line like this
      1111111111:10
      1111111111:11
      1111111111:12
      1111111111:13
      .
      .
      .
      1111111111:20
      2222222222:10
      2222222222:11
      2222222222:12
      2222222222:13
      .
      .
      .
      .2222222222:20
      and so on.
      is there any way to do it ?

      1 Reply Last reply Reply Quote 0
      • Terry RT
        Terry R
        last edited by Terry R

        @Rana-Jawad said:

        i want to put incrementing numbers from 10 to 20

        From your example it would appear that for each line you originally have you want to copy that 10 extra times (?, 10-20 inclusive) and each line will have that incremented number after a :. Is that correct?

        Or does the file already have ALL lines, and you just want the incremented number behind each?

        Terry

        1 Reply Last reply Reply Quote 2
        • Rana JawadR
          Rana Jawad
          last edited by

          i have file like this
          1111111111:
          2222222222:
          3333333333:
          4444444444:
          5555555555:
          i have not duplicated each lines 11 times.
          and i want incremented number from 10 to 20 after each line

          1 Reply Last reply Reply Quote 0
          • Terry RT
            Terry R
            last edited by

            @Rana-Jawad
            Before you use the regex (below) please add 1 additional line to the bottom of the file, this makes the regex easier to code. So Ctrl-End key combo, then hit enter (return) key once.
            So the regex to duplicate each line 10 additional times, each with it’s own incrementing number is, using the Replace function.
            Find What:(\d+:)(\R)
            Replace With:\110\2\111\2\112\2\113\2\114\2\115\2\116\2\117\2\118\2\119\2\120\2

            As this is a regex (regular expression) the search mode MUST be ‘regular expression’ and have wrap around ticked.

            Last step is to remove that last line at the bottom of the file.

            Please let me know how you get on.

            Terry

            1 Reply Last reply Reply Quote 4
            • Rana JawadR
              Rana Jawad
              last edited by

              thank you so much. it worked like charm

              1 Reply Last reply Reply Quote 1
              • guy038G
                guy038
                last edited by

                Hello, @rana-jawad, @terry-r and All,

                I think that we could generalize the process in order to match other texts or number of lines !

                I’ve thought about this general template :

                \h*   Val_1   SP+   Val_2  SP+  Val_3   SP+  Val_4  SP+ ............. SP+  Val_N   TAB+   REPEATED text
                

                where :

                • The first value Val_1 can be preceded with possible horizontal blank characters

                • The different values Val_1, Val_2, Val_3, etc…, are separated with, at least, 1 space character

                • After the last value Val_N , there is, at least, 1 tabulation character, as a separator

                • Finally each line ends with some text, which will be repeated N times, at beginning of the replaced lines

                Now, let’s assume this initial text :

                		  10 11 12 13 14 15 16 17 18 19 20		1111111111:
                100 110 120 130 140 150							ABCDE = -
                10 11 12 13 14 15 16 17 18 19 20				2222222222:
                		  Test									A small 
                    A    B CDE     F GH I						Upper Letters:
                05 05 05 05 05 04 04 04 04 03 03 03 02 02 01	Hesitant Countdown --> 
                

                With this regex S/R :

                SEARCH (?-s)^\h*(\w+)(?=.*\t+(.+))|^\t.+\R?

                REPLACE ?1\2\1\r\n

                You would obtain :

                1111111111:10
                1111111111:11
                1111111111:12
                1111111111:13
                1111111111:14
                1111111111:15
                1111111111:16
                1111111111:17
                1111111111:18
                1111111111:19
                1111111111:20
                ABCDE = -100
                ABCDE = -110
                ABCDE = -120
                ABCDE = -130
                ABCDE = -140
                ABCDE = -150
                2222222222:10
                2222222222:11
                2222222222:12
                2222222222:13
                2222222222:14
                2222222222:15
                2222222222:16
                2222222222:17
                2222222222:18
                2222222222:19
                2222222222:20
                A small Test
                Upper Letters:A
                Upper Letters:B
                Upper Letters:CDE
                Upper Letters:F
                Upper Letters:GH
                Upper Letters:I
                Hesitant Countdown --> 05
                Hesitant Countdown --> 05
                Hesitant Countdown --> 05
                Hesitant Countdown --> 05
                Hesitant Countdown --> 05
                Hesitant Countdown --> 04
                Hesitant Countdown --> 04
                Hesitant Countdown --> 04
                Hesitant Countdown --> 04
                Hesitant Countdown --> 03
                Hesitant Countdown --> 03
                Hesitant Countdown --> 03
                Hesitant Countdown --> 02
                Hesitant Countdown --> 02
                Hesitant Countdown --> 01
                

                Nice, isn’t it !

                Best Regards,

                guy038

                1 Reply Last reply Reply Quote 4
                • Terry RT
                  Terry R
                  last edited by

                  @guy038 said:

                  we could generalize the process

                  I REALLY like that regex, however I wonder if it would be worth it as in the OP’s situation it would be a toss up as to whether my regex or your’s is the easier to set up.

                  The power (and beauty) of your regex lies with the shortness of code, and I should say it’s generalization. Even if there were say 50 numbers to be used (50-99), your regex still looks good, mine on the other hand becomes unwieldy.

                  Thanks for the enlightenment
                  Terry

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