Article 5E4C0 Replace all instances of a string in a file

Replace all instances of a string in a file

by
iicapn
from LinuxQuestions.org on (#5E4C0)
I'm trying to script a hostname change... for instance in my /etc/hosts file, I have a line that says:

Code:127.0.1.1 debian10.mydomain.com debian10If I run the following on the command line, it shows me what I want:

Code:sed 's|debian10|mybox|g' /etc/hostsBut it doesn't replace my /etc/hosts file... it just shows me the changes.

adding ` > /etc/hosts` to the end doesn't seem to help. Is this the best way to replace a string in a file?

Many thanks in advance :-)latest?d=yIl2AUoC8zA latest?i=B-1vsKQ0ox0:lDIc6CnfXek:F7zBnMy latest?i=B-1vsKQ0ox0:lDIc6CnfXek:V_sGLiP latest?d=qj6IDK7rITs latest?i=B-1vsKQ0ox0:lDIc6CnfXek:gIN9vFwB-1vsKQ0ox0
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments