Hereâ€™s a really quick way to edit a bunch of files in a search and replace manner. For example, I had 80 files for sending test transactions and had to change the IP Addr when I copied them to each server. I could have manually edited each one, but by using the following, I was able to change it in all 80 in a matter of about 10 seconds. Itâ€™s done using â€œperlâ€ from the command line and is similar to using global replaces within â€œviâ€ if youâ€™ve ever used that.
perl -pi -e â€™s/wordToFind/replaceWithThisWord/â€™ *.fileExtension
perl -pi -e â€™s/wordToFind/replaceWithThisWord/gâ€™*.fileExtension
perl -pi -e â€™s/wordToFind/replaceWithThisWord/giâ€™*.fileExtension
Remember to escape any special characters like â€œ*â€, â€œ.â€, etc by putting a â€œâ€ in front. Hereâ€™s the command I used this morning that shows what I mean:
perl -pi -e â€™s/220.127.116.11/18.104.22.168/gâ€™ *
The above command replaces 22.214.171.124 with 126.96.36.199 in all the files in the directory I was working in. I put the â€œâ€ in front of the â€œ.â€ to instruct perl to ignore the special meaning of the â€œ.â€