Community
    • Login

    Automated Search & Replace help please

    Scheduled Pinned Locked Moved General Discussion
    3 Posts 2 Posters 590 Views 1 Watching
    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.
    • Ramses505R Offline
      Ramses505
      last edited by PeterJones

      I have a file where I want to do an extensive search and replace utilizing a subtitutions.txt file containing all the search terms and their replacements. The search terms often have spaces in their names like;

      User Logged Off.ico
      

      The replacement may also have multiple spaces like;

      User Logged Off 32.ico
      

      I have installed Python Script and have been trying to get a couple of scripts I found to work, but they use single word search and replace terms.

      This is the main script I have tried;

      with open('C:/Temp/Substitutions.txt') as f:
          for l in f:
              s = l.split()
              editor.replace(s[0], s[1])
      

      If I change the split seperator to (‘#’) it seems to work except I get and extra LF character after every replace which destroys the code.

      Notepad+ is such a brilliant product and I had not realised that you could use Python with it - it’s great that it has pushed me to try and get to grips with Python, even though it is proving frustrating at the monment.

      Any help much appreciated. Thanks for reading.

      --
      moderator added text block to make question clearer

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA Offline
        Alan Kilborn @Ramses505
        last edited by

        @tobias-ray said in Automated Search & Replace help please:

        I get and extra LF character after every replace which destroys the code

        Try s = l.rstrip('\n\r').split('#')

        1 Reply Last reply Reply Quote 2
        • Ramses505R Offline
          Ramses505
          last edited by

          @alan-kilborn said in Automated Search & Replace help please:

          s = l.rstrip(‘\n\r’).split(‘#’)

          Hi alan-kilborn, thanks so much for the help. In my simple test, that does solve the problem, appreciated.

          I will now give it a try for real and no doubt realise a few further issues.

          Thanks again.

          1 Reply Last reply Reply Quote 1

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors