Shawn_Walsh

Replacing a string in all files in a directory

Blog Post created by Shawn_Walsh Employee on Nov 11, 2014

If you are not a Unix guru, you may not know about the power of sed and string manipulation.

This tool can come in very handy when you need to replace a string in all files in a directory.

 

 

sed -i 's/old-word/new-word/g' *.txt

 

below I change to https and port 8443

 

sed -i 's/http:\/\/MACHINENAME:8080\//https:\/\/MACHINENAME:8443\//g' *

 

This is less error prone than manually editing multiple files. It can also be scripted.

 

If you are using Windows, there are versions of 'sed'  you can download.

Outcomes