Inaccurate lines using bash script

# deb http://archive.canonical.com/ubuntu lucid partner # deb-src http://archive.canonical.com/ubuntu lucid partner 

above the lines from /etc/apt/sources.list . There are a number of lines. How to split above 2 lines using a bash script.

+4
source share
3 answers

I would say

  sed -e "s/^# deb/deb/g" /etc/apt/sources.list 

Instead

  sed -e "s/^# //g" /etc/apt/sources.list 

because the second sed command will either uncomment such lines:

 # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to # newer versions of the distribution. 
+5
source

the accepted answer from @ m0ntassar works, but it will uncomment all the lines starting with # deb that can open access to repositories that you don't need - or need -access to.

Instead, I would recommend the following targeting lines:

  • Lines starting with deb but commented out with # as follows: # deb .
  • And lines that end with partner .

So my suggested Sed command would be as follows:

 sed -e "/^#.*deb.*partner$/s/^# //g" /etc/apt/sources.list 

This command with the -e command will show you the output, but the -i flag will edit the file in place:

 sudo sed -i "/^#.*deb.*partner$/s/^# //g" /etc/apt/sources.list 

Running it as sudo in this example, since in-place editing will require sudo rights.

+2
source

You can use sed to replace #

  sed -e "s/^# //g" /etc/apt/sources.list 
+1
source

All Articles