使用sed删除包含斜线的行/ [英] using sed to delete lines containing slashes /

查看:62
本文介绍了使用sed删除包含斜线的行/的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在某些情况下,/之外的其他字符也可以在 sed 表达式中使用:

I know in some circumstances, other characters besides / can be used in a sed expression:

sed -e's.//..g'文件//替换为 file 中的空字符串,因为使用.作为分隔符.

sed -e 's.//..g' file replaces // with the empty string in file since we're using . as the separator.

但是,如果要删除与 file 中的//comment 相匹配的行怎么办?

But what if you want to delete lines matching //comment in file?

sed -e'.//comment.d'文件返回

sed: -e expression #1, char 1: unknown command: `.'

推荐答案

您仍可以使用备用分隔符:

You can use still use alternate delimiter:

sed '\~//~d' file

只需跳过一次定界线的起始点即可.

Just escape the start of delimeter once.

这篇关于使用sed删除包含斜线的行/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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