Community
    • Login

    How to add the numbers in sequence to specific text;

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 3 Posters 784 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.
    • Garbage GoldG
      Garbage Gold
      last edited by

      Hi i have a file like this:

      358
      293
      commit;
      866
      511
      commit;
      58
      767
      commit;
      562
      644
      commit;
      163
      569
      commit;
      414
      305
      commit;
      

      i am wanted to get the output like this;

      358
      293
      commit;1
      866
      511
      commit;2
      58
      767
      commit;3
      562
      644
      commit;4
      163
      569
      commit;5
      414
      305
      commit;6
      

      Like i am wanted to add the numbers in sequence; how can i do this with notepad++

      astrosofistaA 1 Reply Last reply Reply Quote 0
      • astrosofistaA
        astrosofista @Garbage Gold
        last edited by astrosofista

        @Garbage-Gold

        This can be accomplished in a very similar (and easier) way as showed in my reply to your other question.

        Ref.: https://community.notepad-plus-plus.org/post/51862

        So, select the first semi colon ; , then apply Ekopalypse’s Python script to get all of them. Press the Right Arrow, open the Column Editor and enter data as needed. That’s all.

        BR

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

          Hello, @garbage-gold, @astrosofista and All,

          Of course, regexes cannot perform, generally, mathematical operations, but we can cheat a bit !

          • First, open the Replace dialog

            • SEARCH (?<=\d)\R ( or (?<=\w)\R if your text contains words instead of numbers )

            • REPLACE \t

            • If necessary, tick the Wrap around option

            • Select the Regular expression search mode

            • Click on the Replace All button

          => Your text in changed as below, with a TAB char between each word :

          358	293	commit;
          866	511	commit;
          58	767	commit;
          562	644	commit;
          163	569	commit;
          414	305	commit;
          

          Notes

          • This regex S/R looks for any EOL character(s), which is/are preceded with a number ( (?<=\d) ) ( or a word if (?<=\w) )

          • And replaces it with a tabulation character ( \t )


          • Now, put the caret at the end of the first line

          • Open the column editor ( Alt + C )

            • Select Number to Insert

            • Type in 1 in all the zones

            • If necessary, tick the Leading zeros option

            • Click on the OK button

          • Remove additional numbers on possible empty lines, at the end of the list

          You should get :

          358	293	commit;1
          866	511	commit;2
          58	767	commit;3
          562	644	commit;4
          163	569	commit;5
          414	305	commit;6
          

          • Finally, perform the last regex S/R, below :

            • SEARCH \t

            • REPLACE \r\n ( or \n only for Unix files )

          Here is your expected text :

          358
          293
          commit;1
          866
          511
          commit;2
          58
          767
          commit;3
          562
          644
          commit;4
          163
          569
          commit;5
          414
          305
          commit;6
          

          Et voilà !

          Best Regards,

          guy038

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