Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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-->
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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