How to replace string in file with sed in Linux

If you need to quickly replace a string in a file from Linux command line, ‘sed’ will quickly become one of your best friends.

To replace the string “cloud” with “balkan” in the file demo1.txt

sed -i -- 's/cloud/balkan/g' demo1.txt

You can aswell replace string in multiple files by using any file masks:

sed -i -- 's/cloud/balkan/g' *
sed -i -- 's/cloud/balkan/g' *.txt