查找并替换文件中的配置行
我正在尝试编写一个 bash 脚本来在配置文件中进行一些替换。
conf 测试文件是这样的:
pm.max_children = 50
bla bla bla pm.max_children
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 30
;pm.max_requests = 20000
我需要做的替换是:
pm.max_children = 5
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 2000
我需要从 bash 脚本运行这个程序。
I am trying to program a bash script to make some substitutions in a configuration file.
The conf test file is like this:
pm.max_children = 50
bla bla bla pm.max_children
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 30
;pm.max_requests = 20000
The substitutions I need to make are:
pm.max_children = 5
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 2000
I need to run this program from a bash script.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是使用 sed 的更简单的版本:
您可以将其放入单独的文件中并从脚本中调用它吗?
我同意 Kerrek SB 的观点——如果你能解释一下你想要实现的目标,这将会有所帮助!
Here's a simpler version using sed:
Can you put that in a separate file and call it from your script?
I agree with Kerrek SB – it would help if you'd explain what you're trying to accomplish!