Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sed delete option change of delimiter

Tags:

sed

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

like image 822
pokero Avatar asked Oct 31 '13 17:10

pokero


1 Answers

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 (\).

like image 195
devnull Avatar answered Oct 08 '22 00:10

devnull