File_Checkブロックのnotification_intervalを15から2に変更したいと思います。
File_Check行を次のように一致させた後、行6を変更してみました。
sed -e '6 /File_Check/ s/15/2/g' file.txt
しかし、うまくいきません。
これはfile.txtです。
define service {
host_name local
service_description Memory
check_command check_nrpe
max_check_attempts 3
check_interval 5
retry_interval 1
check_period 24x7
notification_interval 15
contact_groups test
notification_period 24x7
notifications_enabled 0
notification_options w,c
_xiwizard nrpe
register 1
}
define service {
host_name local
service_description File_Check
check_command check_nrpe
max_check_attempts 3
check_interval 5
retry_interval 1
check_period 24x7
notification_interval 15
contact_groups test
notification_period 24x7
notifications_enabled 0
notification_options w,c
_xiwizard nrpe
register 1
}
ベストアンサー1
sed '/File_Check/,/contact_groups/ s/\(notification_interval\s*\)15/\12/g' file.txt
これは「File_Check」に一致する行で始まり、「contact_groups」に一致する行で終わり、「notification_interval」が行の「15」の前に来ると、「15」を「2」に置き換えます。