sed 中的变量 [英] variable in sed

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

问题描述

如何使用变量作为 sed 的模式查找器?例如:

how can I use a variable as a pattern finder for sed? for example:

sed -i '/$pc/ s/off/on/' ~/Documents/Mantenimiento

我知道在 '' 之间有一个 $,但一定有办法!请帮忙!

I know there is a $ in between the '' but there gotta be a way! please help!

推荐答案

使用双引号代替单引号,或者在变量之前关闭引号并在变量之后重新打开它们.

Use double quotes instead of single quotes, or close the quotes just before the variable and reopen them just after.

sed -i "/$pc/ s/off/on/"
sed -i '/'$pc'/ s/off/on/'

这将让 bash 正常执行变量评估.

This will let bash perform the variable evaluation normally.

这篇关于sed 中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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