I’m using the following script to replace a configuration file. As example, I’m trying to create an auto-configuration for setting up PXE boot service. YAST maybe the best tools to do what I want, but YAST need a few step to do.Â I couldÂ make a same result with a simple task by preparing default configuration file (the successful configuration on my server), ask some question and thenÂ automatically replace some words with the answer.
You may also use the following script on hosting service :
#!/bin/bash search_dir="/home/vavai/pxe-preconfig/" str="vavai.com" repl_str="vavai.net" for file in $(grep -l -R $str $search_dir) do sed -e "s/$str/$repl_str/ig" $file > /tmp/tempfile.tmp mv /tmp/tempfile.tmp $file echo "File has been successfully modified!" $file done echo "Done !"
If you need to get the dynamic process, modify the script to ask some question and then replace the sed variable with the answer.
But, how if we want to replace multiple string ? Well, it should be easy to use multiple regular expression on sed parameter as below :
sed -e "s/$str1/$repl_str1/ig" -e "s/$str2/$repl_str2/ig" -e "s/$str3/$repl_str3/ig"