How to comment out a string in xml file in shell

2019-08-31 09:21发布

<?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

3条回答
Anthone
2楼-- · 2019-08-31 09:41

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.

查看更多
\"骚年 ilove
3楼-- · 2019-08-31 09:51

This should work

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

查看更多
我只想做你的唯一
4楼-- · 2019-08-31 09:52

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
查看更多
登录 后发表回答