Menu

rereplace fails on bigger files

Help
2016-10-17
2016-10-20
  • Daniel Kovacs

    Daniel Kovacs - 2016-10-17

    Hi folks,

    I'm quite new to Python Script for NPP, butI think i go fine with regexes, python and notepad++ itself.
    I want to make a simple task automatic for data conversion between two different database types, with different fields and different values also. I was thinking that npp + automatic replace will do the job for me, but it seems like not working.
    First of all, sometimes notepad++ throws an unhandled exception and simply crashes when running the script (Win 10 64 Bit).
    But if it does not, the script goes wrong 9 times from 10, but not at the same place in the file. The data is surely not corrupt, because fail occurs on different records.
    I export the data from the original db to JSON, and run this simple script on it:

    Npp.editor.rereplace('},','},\n')
    Npp.console.write("\n1 record 1 line - OK\n")

    sometimes it catches a record, and cut it somewhere, and insert it somewhere else (like part of the 25500th record is between the 12345th and 12346th one, and the other part stays where it belongs to. But this messes up the whole JSON.
    almost every time from a different record nr (but mostly over 10k and under 25k) it starts to place two "}" instead of one.
    sometimes it replaces line endings with unsupported characters (some interesting things, unreadable characters occur instead of line breaks), moreover when i see these, the app crashes every time too.

    The file is about 4.5 MB, and contains 30-40k records, at first time in a single line, this would be the step what gives each record a different line. The script itself does not fail, it writes to the console, moreover if i insert other replacements (like getting ride of some variables, or changing the name of some others), it work well. Seems like only this part is messing up the whole think.

    Does anyone has any idea what's happening? What am i missing? Could my regex be wrong?

    Thanks for answering,
    D K

     
  • CFrank

    CFrank - 2016-10-18

    I assume you wanna replace the literals }, with },\n
    If so, the regex is incorrect as } is a known regex operator char (repeating operator) and therefore you
    need to escape it in order to treat it as a literal. So I guess the regex engine gets
    called too many times with closing repeating char and then at some point npp crashes.
    Not nice but ...
    In addition, you don't need to add Npp in front of your calls editor.rereplace('},','},\n')
    should work as well.
    Btw. in order to test your regex I would recommend to take a little amount of your data
    put it into an document, open the console and test your call. Most of the times you will
    get useful error hints.

    Cheers
    Claudia

     
  • CFrank

    CFrank - 2016-10-18

    btw. there is a known issue that the backup functionality might jump in wile doing replacing and under some strange circumstances it corrupts the doc content. Not sure if this has been fixed with latest version but I normally disable backup
    when editing big files.

    Cheers
    Claudia

     
    • Dave Brotherstone

      I was going to suggest making sure you're on the latest version. These
      issues should be fixed - you should be on 1.0.8, which can only be properly
      installed with the msi until the new plugin manager is released. If you're
      on the latest version, I'd be really grateful if you could share the
      document (privately if you'd prefer)

      We should be rid of these issues, if they still exist we need to track them
      down!

      On Tue, 18 Oct 2016, 15:08 CFrank, myxin2010@users.sf.net wrote:

      btw. there is a known issue that the backup functionality might jump in
      wile doing replacing and under some strange circumstances it corrupts the
      doc content. Not sure if this has been fixed with latest version but I
      normally disable backup
      when editing big files.

      Cheers
      Claudia


      rereplace fails on bigger files


      Sent from sourceforge.net because you indicated interest in <
      https://sourceforge.net/p/npppythonscript/discussion/1188886/>

      To unsubscribe from further messages, please visit <
      https://sourceforge.net/auth/subscriptions/>

       
      • CFrank

        CFrank - 2016-10-18

        Just to be sure, you responded to the original poster, didn't you?
        You are right, I nearly forgot that there was an issue with the older python script version.

        Cheers
        Claudia

         
  • Daniel Kovacs

    Daniel Kovacs - 2016-10-20

    Hi there, thanks for answering!

    First of all, I'm currently escaping the '}' brackets, maybe the text editor here removed them. My script was looking like this (originally, before Claudia's suggestion too).

    Npp.editor.rereplace('\},','\},\n')
    

    Will try to check this for a smaller file with about 1-200 entries only.

    And Dave, thanks for mentioning that i did not annotated the code here, will do that in the future.

    I will share the document privately with you, Dave.

    My version is 1.0.6.0., could this be the problem? Installed via plugin manager.

    Have a nice day,
    D K

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.