Hammad
Hammad

Reputation: 3

How to comment out a string in xml file in shell

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE sailpoint PUBLIC 'sailpoint.dtd' 'sailpoint.dtd'>
<sailpoint>
<ImportAction name='include' value='custom/Application/CARD/CommonCardFiles/COF Imaging Applications Custom Object.xml'/>
<ImportAction name='include' value='custom/Configuration/COF - Singlenter code heree Entitlement Application Custom Object.xml'/>
<ImportAction name='include' value='custom/Rule/COF Related Application Library.xml'/>
<ImportAction name='include' value='custom/Form/COF LCM CBT Form.xml'/>
<ImportAction name='include' value='custom/Workflow/COF Identity Refresh Bypass.xml'/>
<ImportAction name='include' value='custom/Configuration/COF Unstable Roles Config.xml'/>
<ImportAction name='include' value='custom/Application/CARD/CommonCardFiles/COF Salesforce Common Correlation Rule.xml'/>
<ImportAction name='include' value='custom/Rule/COF Single SOD Violation Detection Rule.xml'/>
<ImportAction name='include' value='custom/Configuration/COF APPLICATION DEPENDENCY 
</sailpoint>*

On above mention code i am trying to comment out all the line with pattern custom/Application in it

sed command i use that is not working

sed '/<custom&Application>/s/\(.*\)/<--\1-->/' est.xml > new.xml

Upvotes: 0

Views: 3183

Answers (3)

glenn jackman
glenn jackman

Reputation: 247002

XML data should be parsed with an XML parser.

You can delete those tags with

xmlstarlet ed -d '//ImportAction[contains(@value,"custom/Application")]' file.xml

I'm not sure how to comment them.

Upvotes: 2

Walter A
Walter A

Reputation: 20022

You can match the complete lines with custom and Applicatioin in it. Use & for the matched string.

sed 's/.*custom.*Application.*/<!--&-->/' est.xml > new.xml

Upvotes: 2

LMC
LMC

Reputation: 12777

This should work

sed -e '/custom\/Application/s/\(^.*$\)/<!--\1-->/' est.xml > new.xml

Upvotes: 3

Related Questions