如何在 ruby​​ 中找到並用字串替換模式?

如何在 ruby​​ 中找到並用字串替換模式?

我的文件是:

    [root@test 等]# cat nrpe.cfg
指令[check_users]=/usr/local/nagios/libexec/check_users -w 30 -c 35 指令[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20 指令[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1 指令[check_hda]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sdb 指令[check_procs]=/usr/local/nagios/libexec/check_procs -w 200 -c 250
我想更換/dev/sdb/dev/xvda1在紅寶石中

答案1

File.write('nrpe.cfg', File.read('nrpe.cfg').gsub('/dev/sdb', '/dev/xvda1'))

相關內容