gpt4 book ai didi

linux - 从模板创建多个文件并即时替换内容

转载 作者:太空宇宙 更新时间:2023-11-04 10:09:10 25 4
gpt4 key购买 nike

如标题所述,我想从模板创建多个文件并即时替换固定关键字

如果我这样做

$ 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;

我很好奇这是否可以使用一些单行命令来完成

最佳答案

for i in 01 02 03; do sed "s/XX/$i/" template.conf > template$i.conf; done

关于linux - 从模板创建多个文件并即时替换内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50139840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com