Search this site


Metadata

Articles

Projects

Presentations

Strip XML comments with sed

sed -ne '/<!--/ { :c; /-->/! { N; b c; }; /-->/s/<!--.*-->//g }; /^  *$/!p;'
You might consider stripping blanklines and/or filtering through xmllint --format to make the xml pretty printed.

1 responses to 'Strip XML comments with sed'

Showing last 1 comments... (Click here to view all comments)

Ananya Bhaduri wrote at Fri Jan 18 11:50:30 2008...
Hi,

cat $moduleDepsFile \
  | sed -ne "/<!--/ { :c; /-->/! { N; b c; }; /-->/s/<!--.*-->//g }; /^  *$/!p;" > $moduleDepsF
ile.stripped

I am using this command to strip xml comments and it appears to work on linux; i tried to port the same code on solaris and the commands fails saying

sed: Label too long: /<\!--/ { :c; /-->/\! { N; b c; }; /-->/s/<\!--.*-->//g }; /^  *$/\!p;

Please help..


Leave a reply

You need javascript enabled to use this form. Anti-spam efforts ongoing. Also, if the comment doesn't show up, it's because the form expired. Go back and copy your comment, reload the form, and resubmit. Apologies if this is a hassle, I'm just playing with antispam methods right now. If this insists on not working, please email me about it.

Name (required)
E-mail (optional, if you want me to be able to email you back)
URL (also optional)
Comment: