1

I've been using Xmlstarlet to modify some .xml files but I am lost trying to figure out how to modify a tag based on a partial name. What is the best way to comment out an entire line that begins with < and ends with > when the line has a name of spiral in it?

1

I would use sed for that task:

sed -r -e 's/^<(.*spiral.*)>$/<!--\1-->/'

Demo:

$ cat test.xml 
<some line here>
<other spiral line here>
$ sed -i -r -e 's/^<(.*spiral.*)>$/<!--\1-->/' test.xml 
$ cat test.xml 
<some line here>
<!--other spiral line here-->

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.