Reputation: 130
I need to replace a line in file with something
#Banner none
to
Banner /etc/motd
I tried:
sed -i "s/^#Banner none/Banner /etc/motd/" /root/testfile.sh
which is not working. Do you know how I can do what I want?
Upvotes: 3
Views: 134
Reputation: 163
You'll need to escape your slash or use a different separator than "/".
Could use
sed -i "s/^#Banner none/Banner \/etc\/motd/" /root/testfile.sh
or
sed -i "s,^#Banner none,Banner /etc/motd," /root/testfile.sh
Upvotes: 2
Reputation: 17722
Since you have slashes in the replacement, you should use other separators than slashes, e.g. commas:
sed -i "s,^#Banner none,Banner /etc/motd/," /root/testfile.sh
Otherwise, you'd have to escape the slashes in the path:
sed -i "s/^#Banner none/Banner \/etc\/motd/"
Upvotes: 3