Friday, 30 January 2015

Sed replace entire line after match in XML



I want to replace a line in an XML once I identify the correct tag.


Take



<root>
<My_Name>Andrew</My_Name>
<My_Age>94</My_Age>
</root>


I would like to replace Andrew with Bob


where Bob is stored in $nameVariable


Using sed,



sed -i 's/<My_Name>.*</My_Name>/<My_Name>$nameVariable</My_Name>/g'


This is probably failing due to the lack of escape characters, which I've tried putting in different places, but don't seem to get them right. Help would be much appreciated.


No comments:

Post a Comment