Reputation: 71
cat fxmgr/wrapperwin32.xml | sed '//d' | sed '//d' > cleaned.xml
This will remove the comments from the xml file but I want to replace the comments with the empty lines because I dont want to disturb the other code line numbers.
ex:
line one
xml comment
xml comment
line four
line one
line four
Assume 2 and 3 have the xml comments in the code. we just remove those lines and maintain the empty line. I am not able to add the exact xml comments here.So hope the above ex clarifies it.
Real Example as presented in comments:
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!---Students grades are uploaded by months---->
3 <class_list>
4 <student>
5 <name>Tanmay</name>
6 <grade>A</grade>
7 </student>
8 </class_list>
output
1 <?xml version="1.0" encoding="UTF-8" ?>
2
3 <class_list>
4 <student>
5 <name>Tanmay</name>
6 <grade>A</grade>
7 </student>
8 </class_list
Target : Replace contents of comment line 2 with spaces (and every other comment line in xml file similar to line 2)
Upvotes: 0
Views: 114
Reputation: 6345
To replace comment lines of your xml file that according your comment have this format:
2 <!---Students grades are uploaded by months---->
You can use
sed 's/<!--.*-->/ /g' test.xml
s/
: replace operation for sed (format 's/oldtext/newtext/g')
Tip : As newtext we just put a single space.
/g
: is used for global replacement of all lines.
You can apply changes to the same file using sed -i
, or you can redirect the output to another file by appending >newfile.xml
in the end of the sed command.
Upvotes: 1
Reputation: 1
From googling I got that.
This is the command which deletes the commented lines in the XML file.
cat fxmgr/wrapperwin32.xml | sed '/<!--.*-->/d' | sed '/<!--/,/-->/d' > cleaned.xml
But I want to replace this comments with empty spaces.
Upvotes: 0
Reputation: 3603
try this to find and delete with with regular expression pattern matching.
cat fxmgr/wrapperwin32.xml | sed '/\/\//d' > cleaned.xml
Upvotes: 0