使用sed将带有空格的文本替换为带有斜杠的已定义变量 [英] Using sed to replace text with spaces with a defined variable with slashs

查看:53
本文介绍了使用sed将带有空格的文本替换为带有斜杠的已定义变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用sed将带有定义的变量的行替换为空格.

I am trying to use sed to replace a line with spaces with a defined variable.

例如,

我想用$ lan和lan =〜/afile.py

I want to replace 'a dumb string' with $lan, and lan="~/afile.py

我以为那行是

sed "s/a dumb string/$lan/g" file.txt

但是在file.txt中将哑字符串"部分留空.

but this leave the 'a dumb string' part blank in the file.txt.

我的问题似乎很简单.任何帮助深表感谢.

My problem seems simple enough. Any help is much appreciated.

推荐答案

我确定,由于我的@lan变量中带有斜杠,因此我需要使用sed命令:

I determined that because my @lan variable has slashes in it, I need to use the sed command using :

例如

sed "s:a dumb string:$lan:g" file.txt

这可能是一个新手错误,但是我对sed并不熟悉.谢谢您的帮助.

This is probably a novice mistake, but I'm not that familiar with sed. Thank you for your help.

这篇关于使用sed将带有空格的文本替换为带有斜杠的已定义变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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