I have an xml file in which I am searching for the below pattern.
<ServiceConfig Id="554">
<Comment>ECS_OCS_V1_0.0.0.7.32251@3gpp.org</Comment>
<MaxCost>0.000000</MaxCost>
<MaxCostLocalCurrency>true</MaxCostLocalCurrency>
<Atomic>false</Atomic>
<TariffSwitchHandling>external</TariffSwitchHandling>
<CdrAtTollFreeService>false</CdrAtTollFreeService>
<BonusDuringSession>false</BonusDuringSession>
<UserMessagesStartOfSession>true</UserMessagesStartOfSession>
<UserMessagesDuringSession>true</UserMessagesDuringSession>
<UseAccumulatorStartValues>false</UseAccumulatorStartValues>
<ValidityTime Factor="1">120</ValidityTime>
<Volume>
<Total PreferredFactor="1024" Preferred="500" MinimumFactor="1000000" Minimum="0"></Total>
</Volume>
<VolumeQuotaThreshold Factor="1">0</VolumeQuotaThreshold>
<SendQuotaHoldingTime>false</SendQuotaHoldingTime>
<QuotaHoldingTime Factor="1">0</QuotaHoldingTime>
<SendQuotaConsumptionTime>false</SendQuotaConsumptionTime>
<QuotaConsumptionTime Factor="1">0</QuotaConsumptionTime>
</ServiceConfig>
Block having open & close tags as "ServiceConfig" & in which comment tag has the "ECS_OCS_V1_0.0.0.7" string. for this purpose I used the below sed command.
sed -n '/<ServiceConfig Id=/ { :a /<\/ServiceConfig/! { N; ba; }; /<Comment>ECS_OCS_V1_0.0.0.7./ { p; b; }; }' ServiceConfig.xml
This command is working perfectly on linux system but failing on sunOS with below error.
Label too long: /<ServiceConfig Id=/ { :a /<\/ServiceConfig/! { N; ba; }; /<Comment>ECS_OCS_V1_0.0.0.7./ { p; b; }; }
I am not able to understand what is the cause of this trouble.
On solaris (most often by default setting and/of sed version), ;
are not interpreted as new line like on GNU sed, use real new line especialy for label and jump
sed -n '/<ServiceConfig Id=/ {
:a
/<\/ServiceConfig/ !{
N
ba
}
/<Comment>ECS_OCS_V1_0.0.0.7./ {
p
b
}
}' ServiceConfig.xml
or use several -e
action parameter
sed -n -e '/<ServiceConfig Id=/ {' -e ':a' -e '/<\/ServiceConfig/ !{ N; ba' -e '}; /<Comment>ECS_OCS_V1_0.0.0.7./ { p; b' -e'}' -e '}' ServiceConfig.xml