Find / Replace with TOOLBUCKET



  • Hello NPP-experts,

    i would like to add a new line to a big file after a finding section. How can i do this? I have installed the plugin TOOLBUCKET - Multiline Find Replace. Not in every section i need this new line. To example i create a samplefile with car company’s. My idea was with reg exp.
    FIND: (^automarke_._deutschlandDiesel)
    REPLACE: \1\n NEW LINE
    -> does not work

    myfile with more than 120000 lines:

    automarke_opel_deutschland
    Ascona
    Kadett
    Corsa
    Diesel not in every section
    ###Here add a new line###

    automarke_audi_deutschland
    A3
    A5
    A6
    Benzin
    ###NO new line###

    automarke_opel_deutschland
    Ascona
    Kadett
    Corsa
    Diesel not in every section
    ###Here add a new line###

    Thanks a lot



  • @Rübel-Rund

    So you might start with this text (maybe better than your exact example, which embeds meta stuff in it):

    automarke_opel_deutschland
    Ascona
    Kadett
    Corsa
    Diesel
    
    automarke_audi_deutschland
    A3
    A5
    A6
    Benzin
    
    automarke_opel_deutschland
    Ascona
    Kadett
    Corsa
    Diesel
    

    And you want to turn it into this:

    automarke_opel_deutschland
    Ascona
    Kadett
    Corsa
    Diesel
    foobar
    
    automarke_audi_deutschland
    A3
    A5
    A6
    Benzin
    
    automarke_opel_deutschland
    Ascona
    Kadett
    Corsa
    Diesel
    foobar
    

    I don’t think TOOLBUCKET provides you anything over-and-above what standard regular-expression replace gives you for this…

    So really quickly (I’m sure there are better ways) you can do it with this:

    Find what zone: (?-s)automarke_.+?_deutschland(?s).+?^(?:(Diesel).+?^$|$)
    Replace with zone: $0(?1foobar\r\n)

    Note: Assumes Windows line-endings (\r\n).



  • Thanks a lot.

    It works with a little change(REPLACE: $0(HELLO WORLD\r\n) ) in my file.


Log in to reply