将sed与包含点的变量一起使用 [英] Use sed with variable that contains dot

查看:54
本文介绍了将sed与包含点的变量一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在文件中用6.1替换(例如)6.0,而不用6.1替换640

I am trying to replace (for instance) 6.0 by 6.1 in a file, without 640 being replaced by 6.1

我目前有:

sed -i "s/$previousName/$newName/" 'myFile'

我认为解决方案可以在此处,但我找不到正确的解决方案.

I think that the solution could be in here, but I don't find the right solution.

EDIT 这两个字符串都在变量内,并且应该重复的问题不会处理这种情况

EDIT both string are inside a variable and the question this is supposed to be a duplicate of doesn't treat this case

推荐答案

使用内部 sed :

sed -i "s@$(echo $previousName | sed 's/\./\\./g')@$newName@g" myFile

这篇关于将sed与包含点的变量一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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