试图在 ubuntu 上为 sed 转义/ [英] Trying to escape a / for sed on ubuntu

查看:47
本文介绍了试图在 ubuntu 上为 sed 转义/的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 sed 替换文件中的路径.

I am trying to use sed to replace a path in a file.

sudo sed 's/a/b/g' -i /tmp/test

然而变量是

a = /var/lib and 
b = /data/lib

如何转义斜线?

推荐答案

紧跟在 s 命令之后的字符不需要是 /.处理路径时,我使用 :,如:

The character just after the s command doesn't need to be a /. When working with paths, I use :, as in:

sudo sed 's:a:b:g' -i /tmp/test

这篇关于试图在 ubuntu 上为 sed 转义/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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