7

I want to delete lines from a file matching certain strings. These strings contain slashes, i.e. '/'. My problem is that although you can change delimiter with sed for substitution, you cannot seem to do so with the delete option.

I.e. this does not work because of the slash in $x:

sed --in-place "/$x/d" total-list.csv

where $x is for example "http://someurl.com/uri". But you can't seem to change the delimiter when using the d option (I need it to be ~ for example, instead of /).

Can anyone help on this?

Thanks Paul

pokero
  • 1,009
  • 3
  • 13
  • 27

1 Answers1

12

You can say:

sed --in-place "\~$x~d" total-list.csv

Quoting from the manual:

\%regexp%

(The % may be replaced by any other single character.)

This also matches the regular expression regexp, but allows one to use a different delimiter than /. This is particularly useful if the regexp itself contains a lot of slashes, since it avoids the tedious escaping of every /. If regexp itself includes any delimiter characters, each must be escaped by a backslash (\).

devnull
  • 118,548
  • 33
  • 236
  • 227
  • Thanks very much, that seems to work perfectly. Everything in my file is being deleted, but I think that's because of spaces that were in the $x file - will run again and check. I can't mark this as the answer yet, will do once I can. – pokero Oct 31 '13 at 18:18