How can I search for lines beginning with a certain string in an XML file and comment them using perl -pi -e ‘s/string/replacement/g’ /path/file? I know how to use it for basic text replacement but I don’t know how to do this.
Specifically, i want to comment out the all shadow lines:
<button function="close" state="prelight" draw_ops="close_focused_prelight"/>
<button function="close" state="pressed" draw_ops="close_focused_pressed"/>
<shadow radius="8.0" opacity="0.75" color="#abde4f" x_offset="1" y_offset="4"/>
<padding left="7" right="7" bottom="7"/>
to
<button function="close" state="prelight" draw_ops="close_focused_prelight"/>
<button function="close" state="pressed" draw_ops="close_focused_pressed"/>
<!-- <shadow radius="8.0" opacity="0.75" color="#abde4f" x_offset="1" y_offset="4"/> -->
<padding left="7" right="7" bottom="7"/>
The ? indicates a non-greedy match to capture any characters up until ‘/>’, which should match a shadow element even if it is not the only element on a line.
I forgot that you were doing this on the command line. I just validated this with your test input.