I have a new Ubuntu 12.04 VPS. I am trying to write a setup script that completes an entire LAMP installation. Where I am having trouble is appending a line to the /etc/ho
I should point out that sed
(the stream editor) is not actually intended for editing files, although it can be used to do that. (Standard sed doesn't have a built-in mechanism for writing to other than standard output.) A more appropriate tool would be ed.
The following ed script says "find the line containing the (admittedly sloppy) regular expression /127.0.0.1/ and append at the next line." (The lone period tells ed to stop appending.)
ed /etc/hosts <<-'EOF'
/127.0.0.1/a
192.241.xx.xx venus.example.com
.
wq
EOF
That said, you can really just append this line to the end of your /etc/hosts file very trivially:
echo '192.241.xx.xx venus.example.com' >> /etc/hosts