I have an xml file with the format
<movie>
<title>Title</title>
<originaltitle>Original Title</originaltitle>
<id>ID1234</id>
</movie>
I am failing to use sed to merge the original title and the id tags, as below:
<movie>
<title>Title</title>
<originaltitle>ID1234 - Original Title</originaltitle>
</movie>
How can I save the match on the id, and reuse it elsewhere when modifying the title tag ? Note that the id tag is optional and therefore not always present, in which case, the original title should remain the same. I can write a script to loop over the file tags and achieve the same, but I thought someone might come up with an elegant sed solution for this. Any idea ? I can match each entry individually, but I don t know how to preserve one to use it later. So far I've got this, which does not work
sed '/<id>(.*)<\/id>/ {s/<sorttitle>(.*)<\/sorttitle>/<sorttitle>\1 - \2<\/sorttitle>/}' movie.nfo