如何替换文本文件中的$ {}占位符? [英] How to replace ${} placeholders in a text file?

查看:141
本文介绍了如何替换文本文件中的$ {}占位符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个模板文件输出到MySQL,该文件具有 $ {dbName} 的变量。

I want to pipe the output of a "template" file into MySQL, the file having variables like ${dbName} interspersed. What is the command line utility to replace these instances and dump the output to standard output?

推荐答案

Sed

给定template.txt:

Given template.txt:


The number is ${i}
The word is ${word}

我们只需要说:

sed -e "s/\${i}/1/" -e "s/\${word}/dog/" template.txt

感谢Jonathan Leffler提示将多个 -e 参数传递给相同的 sed 调用。

Thanks to Jonathan Leffler for the tip to pass multiple -e arguments to the same sed invocation.

这篇关于如何替换文本文件中的$ {}占位符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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