6

My /etc/apt/sources.list contains this line :

deb http://downloads.sourceforge.net/project/xenlism-wildfire/repo deb/ 

I want to remove that line via sed in command line, so I tried this code but returns error !

$ sudo sed 's:deb http://downloads.sourceforge.net/project/xenlism-wildfire/repo deb/::g' /etc/apt/sources.list
sed: -e expression #1, char 75: unknown option to `s'

I guess the symbol : after http caused this error, but how can I fix it?

0

2 Answers 2

9

You can use any* symbol to delimit the search/replace strings which does not conflict with symbols in the strings, as long as you use it consistently, e.g.:

sudo sed 's#deb http://downloads.sourceforge.net/project/xenlism-wildfire/repo deb/##g' /etc/apt/sources.list

This reduces the need to escape a problematic character (which could be done using \ as an escape).

*I am sure there are exceptions, especially if using older versions of sed, but I'm not aware of any limitations off hand.

6

Run like this:

sudo sed -i '\%^deb http://downloads.sourceforge.net/project/xenlism-wildfire/repo deb%d' /etc/apt/sources.list

The problems I fixed:

  • Use -i flag to modify the file in-place. Without that, the command would just print the output of sed to the screen, without updating the file.
  • Instead of using s/// to replace the line with empty string, I used the d command to delete the line.
  • For the pattern matching, instead of /.../, I used \%...%, because % doesn't appear in the pattern. With /, all occurrences of / would have to be replaced.

Note that possibly a simpler filter might be good enough. For example if you know that xenlist-wildfire is unique in the file, then this simpler command will work too:

sudo sed -i '/xenlism-wildfire/d' /etc/apt/sources.list

Since in this example there is no /, I could use the simpler /.../ filter.

(Thanks for @steeldriver for the improvement ideas.)

1
  • Good points @steeldriver, I improved my answer. Btw, even with the s command he could have used a simpler pattern, as /xenlism-wildfire/s/.*//. Not sure it's worth mentioning though, user seems to be a beginner.
    – janos
    Dec 25, 2016 at 21:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .