Reputation: 1029
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
Upvotes: 7
Views: 2728
Reputation: 123608
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 (\
).
Upvotes: 12