I am trying to create a script that will amnog other things enable source repositories in sources.list (Ubuntu). As you may or may not know the format of the repository file is something like this:
deb http://archive.ubuntu.com/ubuntu/ xenial-updates main restricted
# deb-src http://archive.ubuntu.com/ubuntu/ xenial-updates main restricted
# etc.
So I would like to enable source repository (uncomment lines with deb-src) but only for those preceded by the uncommented deb line. GNU sed should be perfect for this but I'm not able to make this work. This is what I have right now:
sed -i 's/^# deb-src/deb-src/gm' /etc/apt/sources.list
What I would like to have is something like this but it should replace only the commented line not everything:
sed -i 's/^deb .*$^# deb-src/deb-src/gm' /etc/apt/sources.list
So is there a way to make regex for sed that will only replace a part of matched string?