Replace a string in file using shell script?

If you are using a newer version of sed you can use -i to read from and write to the same file. Using -i you can specify a file extension so a backup will be made, incase something went wrong. Also you don't need to use the -e flag unless you are using multiple commands.

If you are using a newer version of sed you can use -i to read from and write to the same file. Using -i you can specify a file extension so a backup will be made, incase something went wrong. Also you don't need to use the -e flag unless you are using multiple commands sed -i .

Bak "s/${line}/${rep}/g" /root/new_scripts/a. Conf I have just noticed that as the variables you are using are quoted strings you may want to use single quotes around your sed expression. Also your string contains a forward slash, to avoid any errors you can use a different delimiter in your sed command (the delimiter doesn't need to be a slash): sed -i .

Bak 's|${line}|${rep}|g' /root/new_scripts/a.conf.

You have to write the changes to a new file and then, move the new file over the old one. Like this: line="Include 2" rep="" sed -e "s/${line}/${rep}/g" /root/new_scripts/a. Conf > /root/new_scripts/a.

Conf-new mv /root/new_scripts/a. Conf-new /root/new_scripts/a.conf.

The redirection (> /root/new_scripts/a. Conf) wipes the contents of the file before sed can see it. You need to pass the -i option to sed to edit the file in-place: sed -i "s/${line}/${rep}/g" /root/new_scripts/a.

Conf You can also ask sed to create a backup of the original file: sed -i. Bak "s/${line}/${rep}/g" /root/new_scripts/a.conf.

Your answer is correct but I have a new problem now. Look at my question again. – Pritom Dec 13 '11 at 10:23 Please don't mind, if this question is mark solved then nobody answered this.

– Pritom Dec 13 '11 at 10:32 Doesn't work. Any other idea please? – Pritom Dec 13 '11 at 10:37 @Pritom see my edited answer – luketorjussen Dec 13 '11 at 10:38.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions