SED替代使用bash变量 [英] sed substitution with bash variables
本文介绍了SED替代使用bash变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
试图在一个bash脚本使用sed的用线来改变一个文本文件中的值,
Trying to change values in a text file using sed in a bash script with the line,
sed 's/draw($prev_number;n_)/draw($number;n_)/g' file.txt > tmp
这将是一个for循环。不知道为什么它不工作。有什么建议?
This will be in a for loop. Not sure why it's not working. Any suggestions?
推荐答案
在变量
没有得到取代在bash。为了得到字符串替换(或内插,如果你熟悉Perl),你需要改变它使用而不是单引号双引号:
Variables inside '
don't get substituted in bash. To get string substitution (or interpolation, if you're familiar with perl) you would need to change it to use double quotes "
instead of the single quotes:
sed "s/draw($prev_number;n_)/draw($number;n_)/g" file.txt > tmp
另外,除非你需要它在不同的文件中,你可以使用 -i
标记来更改文件的地方。
Also, unless you need it in a different file you can use the -i
flag to change the file in place.
这篇关于SED替代使用bash变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文