Modify sources.list from script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Modify sources.list from script
# 1  
Old 02-20-2010
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:
Code:
sed '/*'"$REPO"'/,/'"$STOP"'/ s/^[ #]*//' /etc/apt/sources.list

but this enables both the normal and the source repos.
for example:
Code:
# 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 Smilie

ps, sorry if this is in the wrong section.

Last edited by Leppie; 02-20-2010 at 06:37 PM..
# 2  
Old 02-21-2010
Leppie,

What are the contents of the REPO and STOP variables?

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


Regards
# 3  
Old 02-21-2010
Hi Franklin52,
thanks for your reply.
what i'm trying to do is commenting or uncommenting specific lines. for instance these repositories:
Code:
# 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:
Code:
deb http://www.lamaresh.net/apt lenny main
# deb-src http://www.lamaresh.net/apt lenny main

# 4  
Old 02-21-2010
To uncomment the first line you could do:

Code:
REPO="deb "

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

For the second line:

Code:
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:
Code:
STOP="deb "
REPRO="lamaresh"

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

and:
Code:
STOP="deb-src"
REPRO="lamaresh"

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


Last edited by Franklin52; 02-21-2010 at 11:20 AM..
# 5  
Old 02-21-2010
Frankin52, you're a genius.
i never thought of concatenating the two search terms to narrow down the hits.
thank you very much Smilie
heel erg bedankt, wil je wat bits van mij?
# 6  
Old 02-21-2010
just to give an idea how to do it with awk:

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

regards
# 7  
Old 02-21-2010
EAGL€, that is working very nicely as well.
i think i have to dig a little deeper into sed and (g)awk Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Debian

Repositories in sources.list

I'm just interested to know how your sources.list look like. I got some repositories witch give some errors and I would like to clean it up. and when I do apt-get update I get few lines showing errors like 404 , this is how my list look like: # deb cdrom:/ squeeze main # deb cdrom:/... (0 Replies)
Discussion started by: zdorian
0 Replies

2. Shell Programming and Scripting

Script to List, Modify, replace filename for an upload?

Hello, here is my problem: I have ma program in a first directory dir1: ls path1/rep1/ file1.f90 file1.f90~ file1.o file2.f90 .... etc... I have modified folder in an other directory: ls path2/rep2/ file1_modified.f90 file2_modified.f90 .... etc... All files from first... (8 Replies)
Discussion started by: shadok
8 Replies

3. Shell Programming and Scripting

how can I modify this script.

hello forum members, I have a script which is used find the Uname and passwords and redirects into a output.txt file.I hardcoded a string "ciadev" but iwant search two more strings also "absdev" and "absprod" So modify this script please. I am lookinmg forward from you, please find the below... (2 Replies)
Discussion started by: rajkumar_g
2 Replies

4. Shell Programming and Scripting

List files and display last modify time in a particular format

hi everyone, can someone suggest how i can list the contents of a directory and display their corresponding last modify time in the format yyyymmddhhmm? thanks in advance! (16 Replies)
Discussion started by: Deanne
16 Replies

5. Shell Programming and Scripting

script to modify /etc/shadow

Hi I am looking for script to modify /etc/shadow. For example: 1-)User enters username 2-)The line of that user is found in /etc/shadow and *LK* is added infront of the second field in /etc/shadow. How can I do this? Thanks (7 Replies)
Discussion started by: tjay83
7 Replies

6. Shell Programming and Scripting

Please help to modify my script

Hi, I have a script which connect to ATM's and pull two files from the ATM. The which i try to pull is like PIC20085200001*.JPG First 7 digit consist of year montn and date as well After todays execution i want to change the date to next date I add few lines in the script but it is not... (6 Replies)
Discussion started by: Renjesh
6 Replies

7. Shell Programming and Scripting

Request to modify script to list multiple parameters for V_fieldid variable

I am posting a script below which essentially excutes the following functions in the described order. 1) From a source directory pools together three files generated by system logs for each user session, tar's these files and archives them as a log set in a destination directory and these... (0 Replies)
Discussion started by: Sammy
0 Replies

8. Shell Programming and Scripting

Modify Perl script to work with txt - Permissions script

Hi I have this code, and i want work with a ls -shalR output in .txt What i need read to do this?? Where start? #!/usr/bin/perl # Allrights- A perl tool for making backups of file permissions # Copyright (C) 2005 Norbert Klein <norbert@acodedb.com> # This program is free... (1 Reply)
Discussion started by: joangopan
1 Replies

9. Shell Programming and Scripting

Is it possible in a shell script to modify itself ??

We are running a quiz and the data collected from the quiz is submitted to the database. My requirement is to write a shell script to get these submitted records. I should be able to run this shell script at any time and the records it returns should be the ones submitted after the script was... (5 Replies)
Discussion started by: sehgalniraj
5 Replies
Login or Register to Ask a Question