我們想匹配字符串DataGuardDatadgSpace &找到花括號&內hostgroups字符串與服務器NODE1-替換字符串服務器的數據庫與hostgroups.it匹配的行中的DATABASE不應影響與字符串或其餘代碼相匹配的servicegroups行。匹配字符串找到括號和用大括號匹配另一個字符串替換爲&
我想在一個文件中編輯此代碼。我曾嘗試下面的選項
sed -e '/./{H;$!d;}' -e 'x;/DataGuardDatadgSpace/!d;' test.shee
| sed '/hostgroups/s/\S*$/REPLACED/g'
,但它不是對文件
define service { use generic-pasv-svc name SERVER-DATABASE-ArchdgSpace service_description DataGuardArchdgSpace hostgroups SERVER-DATABASE,xDB servicegroups PASV,SERVER-stack,SERVER-DATABASE max_check_attempts 3 check_command check_dummy!2!"Passive check is stale" contact_groups po check_freshness 1 freshness_threshold 180 register 1 } define service { use generic-pasv-svc name SERVER-DATABASE-DatadgSpace service_description DataGuardDatadgSpace servicegroups PASV,SERVER-stack,SERVER-DATABASE max_check_attempts 3 check_command check_dummy!2!"Passive check is stale" contact_groups po hostgroups SERVER-DATABASE,xDB check_freshness 1 freshness_threshold 180 register 1 } define service{ use generic-pasv-svc name ORA_DATABASE_HangDetect_DefunctProcess service_description ORA_HangDetect_DefunctProcess hostgroups SERVER-DATABASE servicegroups PASV check_command check_dummy!3!"Passive service check is stale, check the Ora HangDetect Script is running or not" freshness_threshold 600 contact_groups po max_check_attempts 2 normal_check_interval 5 retry_check_interval 1 register 1 }
太好了!你有一個問題陳述。到目前爲止你嘗試過什麼,它怎麼不起作用? –
我已經嘗試了以下方法,但並未將其替換爲文件。我的要求是編輯文件中的字符串 – Yeshwanath
sed -e'/./{H;$!d;}'-e'x;/DataGuardDatadgSpace /! d;」 test.shee | sed'/ hostgroups/s/\ S * $/REPLACED/g' – Yeshwanath