Automated Search & Replace help please
-
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.icoThe replacement may also have multiple spaces like;
User Logged Off 32.icoI 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 -
@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('#') -
@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.
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