how to append the numbers with specific string ??



  • hfshfdohoh kamal from which build the issue is comming need to check it out .
    nscknkjnkjdnjknnkjnjd jnnfdnfn kamal from which build the issue is comming need to check it out .
    nndnfdoihiofdhoifdhoi dnidihdi nindiididkamal from which build the issue is comming need to check it out .
    jbffbufb kamal from which build the issue is comming need to check it out .
    hfhfjfj kamal from whickamal from which build the issue is comming need to check it out .
    nidididn kamal from which build the issue is comming need to check it out .
    nnidnid kamal from which build the issue is comming need to check it out .

    in the above text ,wherever kamal is there ,kamal 1 ,kamal 2 ,kamal 3 should come …so out put text should be :-



  • hfshfdohoh kamal from which build the issue is comming need to check it out .
    nscknkjnkjdnjknnkjnjd jnnfdnfn kamal from which build the issue is comming need to check it out .
    nndnfdoihiofdhoifdhoi dnidihdi nindiididkamal from which build the issue is comming need to check it out .
    jbffbufb kamal from which build the issue is comming need to check it out .
    hfhfjfj kamal from whickamal from which build the issue is comming need to check it out .
    nidididn kamal from which build the issue is comming need to check it out .
    nnidnid kamal from which build the issue is comming need to check it out .

    in the above text ,wherever kamal is there ,kamal 1 ,kamal 2 ,kamal 3 should come …so out put text should be :-

    output text:
    hfshfdohoh kamal1 from which build the issue is comming need to check it out .
    nscknkjnkjdnjknnkjnjd jnnfdnfn kamal2 from which build the issue is comming need to check it out .
    nndnfdoihiofdhoifdhoi dnidihdi nindiidid kamal3 from which build the issue is comming need to check it out .
    jbffbufb kamal4 from which build the issue is comming need to check it out .
    hfhfjfj kamal5 from whickamal from which build the issue is comming need to check it out .
    nidididn kamal6 from which build the issue is comming need to check it out .
    nnidnid kamal7 from which build the issue is comming need to check it out .



  • another example:
    input text:
    kamal kamal kamal kamal

    kamal kamal kamal kamal

    output text:
    kamal 1 kamal 2 kamal 3 kamal 4

    kamal 5 kamal 6 kamal 7 kamal 8



  • @kamal-lochan said in how to append the numbers with specific string ??:

    in the above text ,wherever kamal is there ,kamal 1 ,kamal 2 ,kamal 3 should come …so out put text should be :-

    Your examples are not consistent. With one you have the numbers forming part of the word. In the other you have the number trailing the word with a space between.

    Please repost your before and after examples by inserting them into this thread. Then select each group (before and after) separately and use the </> button above the window so that the before and after examples appear in separate black boxes. This helps to prevent any characters being altered by the posting window.

    Also be aware that any solution given will work on the word supplied, I.e. kamal. If this is not the real word you need to explain exactly what you really want. Are there always 4 of the same word on each line, or could this be different, say 1 on a line followed by 3 on the next and a different number on the third. As much detail as you can provide will give us a better chance of providing the optimal solution.

    Please don’t create a new thread, just reply in this thread as all these posts are about the 1 subject matter.

    Terry



  • BEFORE:

    abc xyg kamal typ kamal plo kamal 90u kamal

    zxcv kamal rdfd kamal File kamal kamal opd

    AFTER:i wants below output

    abc xyg kamal 1 typ kamal 2 plo kamal 3 90u kamal 4

    zxcv kamal 5 rdfd kamal 6 File kamal 7 kamal 8 opd



  • BEFORE:
    abc xyg kamal typ kamal plo kamal 90u kamal

    zxcv kamal rdfd kamal File kamal kamal opd

    AFTER:i wants below output
    abc xyg kamal 1 typ kamal 2 plo kamal 3 90u kamal 4

    zxcv kamal 5 rdfd kamal 6 File kamal 7 kamal 8 opd

    in the above text ,i wants to change kamal string to kamal 1 and then kamal 2 and then kamal 3 and then kamal 4 .

    how can i do that .??



  • @kamal-lochan said in how to append the numbers with specific string ??:

    change

    Wherever Kamal string is there i wants to append some number to it .example first time kamal string appeared so i will replace it kamal 1 and for 2nd time kamal string appeared i will replace it kamal 2 and 3rd time kamal 3 and so on …how can i do that .



  • @kamal-lochan

    You will likely have to resort to some sort of programming language solution to make that happen. Notepad++ supports some scripting languages as plugins which can do it. An example is the Pythonscript plugin, where the classic example of it is found in the documentation:

    609cb9f6-05ff-4a1b-852a-f6eb41ae3677-image.png

    In your case that code would be changed to be a bit more complicated:

    count = 0
    
    def add_1(m):
        global count
        count += 1
        return ' ' + str(count)
    
    editor.rereplace(r'(?<=kamal)(?! \d)', add_1);
    

    Here’s one of your earlier example sections of “BEFORE” text:

    hfshfdohoh kamal from which build the issue is comming need to check it out .
    nscknkjnkjdnjknnkjnjd jnnfdnfn kamal from which build the issue is comming need to check it out .
    nndnfdoihiofdhoifdhoi dnidihdi nindiididkamal from which build the issue is comming need to check it out .
    jbffbufb kamal from which build the issue is comming need to check it out .
    hfhfjfj kamal from whickamal from which build the issue is comming need to check it out .
    nidididn kamal from which build the issue is comming need to check it out .
    nnidnid kamal from which build the issue is comming need to check it out .
    

    Here’s what the “AFTER” text looks like after running that script on it:

    hfshfdohoh kamal 1 from which build the issue is comming need to check it out .
    nscknkjnkjdnjknnkjnjd jnnfdnfn kamal 2 from which build the issue is comming need to check it out .
    nndnfdoihiofdhoifdhoi dnidihdi nindiididkamal 3 from which build the issue is comming need to check it out .
    jbffbufb kamal 4 from which build the issue is comming need to check it out .
    hfhfjfj kamal 5 from whickamal 6 from which build the issue is comming need to check it out .
    nidididn kamal 7 from which build the issue is comming need to check it out .
    nnidnid kamal 8 from which build the issue is comming need to check it out .
    


  • @Alan-Kilborn said in how to append the numbers with specific string ??:

    Pythonscript plugin

    Can you please share the steps ;
    1)where i can run python scripits and how the out put wil come on console ??
    Please share the steps+steps scpreen shot if possible



  • ![alt text](![image url](1.png image url))

    i am running python scripts in one tab and in other tab my text is present .

    is thre any thing do i need to do?



  • Hi @kamal-lochan

    Here are some basic hints for getting a Python script to run:

    https://community.notepad-plus-plus.org/post/54655
    

    Once the script is installed, select the text to process and run the script.

    Have fun!



  • @astrosofista said in how to append the numbers with specific string ??:

    select the text to process and run the script.

    Actually, the script runs on the currently-active document (the entire text of the document), not the selected text. We could change it slightly to do that, but that wasn’t requested.



  • That’s what I wanted to write, but my fingers were faster !

    Anyway, my preference is always to process the selected text or it via the clipboard, not the entire document.

    OP, now you know what to do. Go for it !



  • @kamal-lochan said in how to append the numbers with specific string ??:

    Wherever Kamal string is there i wants to append some number to it .

    Here is an alternative option which ONLY involves regular expressions (and the column editor function).

    1. replace all CRLF with @@
      Place cursor in the first position of the file. Using the Replace function we have
      Find What:\R
      Replace With:@@
      Search mode is “regular expression”, click on “replace all”

    2. insert CR & LF before every “kamal” text
      Place cursor in the first position of the file. Using the Replace function we have
      Find What:(([a-z]+)?kamal)
      Replace With:\r\n\1
      Search mode is “regular expression”, click on “replace all”

    3. insert line numbers and move to behind the “kamal” text
      Check if the first line has the “kamal” text, if not position the cursor in the first position of the second line (which does have the “kamal” text). Use column editor and use “number to insert”, starting 1, increase 1 and repeat 1, click OK.

    4. Now to move the number behind the “kamal” text.
      Using the Replace function we have
      Find What:^(\d+)[a-z]+)
      Replace With:\2 \1

    5. recreate the original CRLF and remove the previously inserted ones
      Using the Replace function we have
      Find What:(@@)|\R
      Replace With:?1(\r\n)

    I’n not proposing that you use this method as it seems you are well on the way to solving it the “pythonscript” way which is far more sensible. I’m showing you another method which is very simple to understand but as a consequence has a few steps to it.

    Terry


Log in to reply