Search multiple lines, and replace... with other multiple lines!



  • Dear notepad++ community,

    If you could help, I would really be eternally grateful. I’m not sure whether it’s possible to perform this action… but I’ve tried for almost two days with non optimal solutions.

    What am I trying to do?

    I have a Json file that I’m trying to edit on Notepad++. This file is quite long, 36k lines of code.

    Within this file, there are several instances that I need to replace with other data; about 500+ lines.

    Basically:

    codecodecode
    codecodecode
    “title”: “Dragon ball”
    code code code
    “title”: “Sailor moon”
    code code code
    “title”: “Digimon”
    code code code


    What I need to do is replace those titles with another set of strings. Thing is, I can’t run a search and replace for each one of them… that would be doing it 500+ times…

    What I managed to do on npp, is to bookmark all the istances I want to replace; copy the lines to a new document… but little else… when I cut/remove the lines the whole code shifts up… and I wish it didn’t do that, because then I could maybe paste the values in the remaining gaps maybe?

    If you have an idea on how I could search and replace all those lines in one fell swoop, I would really be thankful! Even if it means using another software… although somehow I think npp is what I need!



  • Can you post an “after” example of your text so I can see how it would be altered? Thinking it should be easy enough to do with a macro…



  • Here’s an example:

    Before:
    codecodecode
    codecodecode
    “title”: “Dragon ball”
    code code code
    “title”: “Sailor moon”
    code code code
    “title”: “Digimon”
    code code code

    After:
    codecodecode
    codecodecode
    “title”: “Death Note”
    code code code
    “title”: "One Piece”
    code code code
    “title”: “Django Unchained”
    code code code

    I hope this helps!



  • Ok! Actually Patrick (thank you Patrick), gave me a great idea.

    I put all the new strings that I was going to substitute at the top of the JSON file.

    Then I ran a search of the “title”: string, and bookmarked each instance.

    Then I ran a macro that:

    Highlighted the first line of the document
    Copied the line.
    Deleted the line. (So the second one would jump up, and the data gets deleted as well)
    Press F2 (to jump to the bookmark)
    Highlight the line
    Paste the line
    Pressed CTRL + F2 (to unmark the line)
    Pressed CTRL + Home (to go back to the top of the file)

    Rinse and repeat!

    Thank you again Patrick for giving me this idea!


Log in to reply