sed 删除选项更改分隔符 [英] sed delete option change of delimiter

查看:58
本文介绍了sed 删除选项更改分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从匹配某些字符串的文件中删除行.这些字符串包含斜杠,即/".我的问题是,虽然您可以使用 sed 更改分隔符以进行替换,但您似乎无法使用 delete 选项这样做.

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.

即由于 $x 中的斜杠,这不起作用:

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

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

其中 $x 是例如http://someurl.com/uri".但是在使用 d 选项时您似乎无法更改分隔符(例如,我需要它是 ~ 而不是/).

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 /).

有人可以帮忙吗?

谢谢保罗

推荐答案

你可以说:

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

引用手册:

\%regexp%

(% 可以替换为任何其他单个字符.)

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

这也匹配正则表达式 regexp,但允许使用与 / 不同的分隔符.这在以下情况下特别有用regexp 本身包含很多斜线,因为它避免了繁琐的转义每个 /.如果正则表达式本身包含任何分隔符字符,每个字符都必须用反斜杠 (\) 转义.

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

这篇关于sed 删除选项更改分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆