0

I create an xmltv.xml for TV listings and need to use SED for some post processing. Im using Windows 10 with SED for Windows run via a bat file. The trouble is only certain tags are shown on my front end so i need to combine sub-title with desc in the xml. I have a current SED command i run to append the sub-title to the title, but can't figure out sub-title to desc.

This is what a channel in the xml looks like, but not all programmes have a sub-title.

  <programme start="20160422223500 -0500" stop="20160422233700 -0500" channel="Channel_ID">
<title lang="en">Program Name</title>
<sub-title lang="en">Subtitle Example</sub-title>
<desc lang="en">Description Example</desc>

This is how i would append a hockey team from the sub-title to the title using sed.txt

cmd

sed.exe -f sed.txt < "xmltv.xml" > "xmltv2.xml"

sed.txt

:a;N;$!ba;s/\(<programme[^<]*\)\(<t[^>]*>\)\(NHL Hockey*[^<]*\)\(<[^<]*\)\(<sub-title[^>]*>\)\([^<]*\)[^<\/programme]*/\1\2\3: \6\4\5\6/g

Can someone please provide a command like above to append the sub-title to desc like this?

<desc lang="en">Subtitle Example : Description Example</desc>
0
sed -nr '/sub-title/ {N;s,/desc,&,;Tprint;s,<sub-title[^>]+>(.*)</sub-title>\n(<desc[^>]+>)(.*</desc>),\2\1 : \3,;:print};p' <<<'<programme start="500 -05" stop="700 -5" channel="Channel_ID">
<title lang="en">Program Name</title>
<sub-title lang="en">Subtitle Example</sub-title>
<desc lang="en">Description Example</desc>

<programme start="600 -05" stop="800 -5" channel="Channel_ID">
<title lang="en">Program Name foo</title>
<desc lang="en">Description Example bar</desc>
> '
<programme start="500 -05" stop="700 -5" channel="Channel_ID">
<title lang="en">Program Name</title>
<desc lang="en">Subtitle Example : Description Example</desc>

<programme start="600 -05" stop="800 -5" channel="Channel_ID">
<title lang="en">Program Name foo</title>
<desc lang="en">Description Example bar</desc>

It's a GNU/Linux sed solution but I think it is easy to adapt to Windows. You can try to use another separator in substitution and the -r option for advanced Regexp to avoid \/ \( \). I wrote some literal tags (</sub-title> </desc>) so if there are some extra blanks you would have to adapt.

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.