正如标题中所述,我想从模板创建多个文件并在运行中替换固定的关键字
如果我这样做
$ sed s/XX/{01..05}/g templates/pXX.conf
我有点接近,因为我得到第一个结果的正确输出,但数字02-04的错误。
因为icinga不需要分隔每个配置文件(但这会是一个奖励),所以可以将结果放到一个输出文件中。
示例:
//template.conf
object Host "pXX" {
display_name = "RasPi XX"
...
}
现在应该导致:
//p01.conf <- ascending filenames would be a bonus
object Host "p01" {
display_name = "RasPi 01"
...
}
//p02.conf
object Host "p02" {
display_name = "RasPi 02"
...
}
// and so on
我很确定通过使用任何带有循环的脚本
可以轻松完成while $i < number: read file; replace content; output file;
我只是好奇是否可以使用一些单行命令来完成
答案 0 :(得分:1)
for i in 01 02 03; do sed "s/XX/$i/" template.conf > template$i.conf; done