Uncoment lines using bash script
# deb http://archive.canonical.com/ubuntu lucid partner
# 开发者_如何学运维deb-src http://archive.canonical.com/ubuntu lucid partner
above lines from /etc/apt/sources.list
.There are number of lines. How to uncomment above 2 lines with bash script.
I'd say
sed -e "s/^# deb/deb/g" /etc/apt/sources.list
Instead of
sed -e "s/^# //g" /etc/apt/sources.list
because th second sed command will either uncomment lines such :
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
The accepted answer from @m0ntassar works, but it will uncomment all lines that begin with # deb
which might open up access to repositories one doesn’t want—or need—access to.
Instead I would recommend targeting lines that are:
- Lines that begin with
deb
but are commented out with a#
like this:# deb
. - And lines that specifically end with
partner
.
So my suggested Sed command would be as follows:
sed -e "/^#.*deb.*partner$/s/^# //g" /etc/apt/sources.list
That command with the -e
command would show you the output, but the -i
flag would edit the file in place:
sudo sed -i "/^#.*deb.*partner$/s/^# //g" /etc/apt/sources.list
Running that as sudo
in this example since editing in place would require sudo
rights.
You can use sed to replace the #
sed -e "s/^# //g" /etc/apt/sources.list
精彩评论