如何在sed中使用变量 [英] How to use variables in sed
本文介绍了如何在sed中使用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在sed命令中使用变量?
How to use variables in sed command?
例如:sed '/Jagan/s/Hi/HELLO/' 文件
这里我想用一个变量替换 Hi
here i want to replace Hi
with a variable
var1=Hi
sed '/Jagan/s/$var1/HELLO/' file
推荐答案
使用 "
而不是 '
:
sed "/Jagan/s/$var1/HELLO/"
双引号 "
允许 shell 扩展字符串内的变量.单引号 '
不允许这样做.
The double quote "
allows the shell to expand variables inside a string. The single quote '
doesn't allow this.
这篇关于如何在sed中使用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文