Modify sources.list from script

i'm looking for a way to enable and disable repositories from a script.
i started with a sed command like this:

sed '/*'"$REPO"'/,/'"$STOP"'/ s/^[ #]*//' /etc/apt/sources.list

but this enables both the normal and the source repos.
for example:

# deb http://www.lamaresh.net/apt lenny main
# deb-src http://www.lamaresh.net/apt lenny main

anybody knows of a way to control just one? e.g. just add/remove the # from the concerning repo line?

all help much appreciated :slight_smile:

ps, sorry if this is in the wrong section.

Leppie,

What are the contents of the REPO and STOP variables?

Give an example of the sourcelist before and after the substitution.

Regards

Hi Franklin52,
thanks for your reply.
what i'm trying to do is commenting or uncommenting specific lines. for instance these repositories:

# deb http://www.lamaresh.net/apt lenny main
# deb-src http://www.lamaresh.net/apt lenny main

could be defined by setting the variable REPO to "lamaresh". however, doing so with the current sed command, it will take both lines while i want to be able to control which line get uncommented.
so i'm looking for something that can search for a string and commit a change in the line containing the search string, but skip the line if another search string is present. i hope this is clear?
so for instance, uncomment/comment if "lamaresh" and "deb" are found, but do nothing if "lamaresh" and "src" are found, with a result like this:

deb http://www.lamaresh.net/apt lenny main
# deb-src http://www.lamaresh.net/apt lenny main

To uncomment the first line you could do:

REPO="deb "

sed "/^# $REPO/ s/^# //" file

For the second line:

REPO="deb-src"

sed "/^# $REPO/ s/^# //" file

If the output is correct you can use the -i option of sed to edit the file "in place".

EDIT: Misunderstand your question, this should be a better approach:

STOP="deb "
REPRO="lamaresh"

sed "/^# $STOP.*$REPRO/ s/^# //" file

and:

STOP="deb-src"
REPRO="lamaresh"

sed "/^# $STOP.*$REPRO/ s/^# //" file

Frankin52, you're a genius.
i never thought of concatenating the two search terms to narrow down the hits.
thank you very much :slight_smile:
heel erg bedankt, wil je wat bits van mij?

just to give an idea how to do it with awk:

awk '/lamaresh/&&/deb / {print "#"$0}'  FILE
awk '/lamaresh/&&/deb-src/ {print $0}'  FILE

regards

EAGL�, that is working very nicely as well.
i think i have to dig a little deeper into sed and (g)awk :slight_smile:

You're welcome! Enne.. ik heb genoeg bits :smiley: