Wednesday, November 22, 2017

notepad++ - Find and Replace several several different values all at once


I have a file with multiple instances of Text_1 and Text1 and I need to replace both those strings with Text_A and TextB respectively.


Currently I'm doing two Find and Replace functions on each file one that finds Text_1 and replaces it with Text_A and the other that finds Text1 and replaces it with TextB.


Is there any way to do this all at once instead of having to run "Find and Replace" twice?


I am using Dreamweaver CS3, but I also have Notepad++, regular Notepad, OO Writer, MS Word if those will be easier. Ideally I could do this in Dreamweaver or Notepad++ but I'm open to downloading something else to get the job done. I'd prefer not to have to do any command line stuff or create a batch file (while I'm aware of it, I don't understand it really).


In case the above description isn't clear, let me explain it this way...


I want to run Find & Replace 1 time in 1 document and I want it to do ALL of the following during that one Find & Replace instance:



  1. Find Text_1 and Replace with Text_A

  2. Find Text1 and Replace with TextB


I am not trying to do a Find and Replace across several documents.


Answer



Take a look at Sed. You can easily achieve your goal by only one command line


sed -e "s/Text_1/TextA/" -e "s/Text1/TextB/" your_file_new.txt


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...