I have got plenty of text files in XML format like this:
<TITLE>title</TITLE>
<TEXT>text</TEXT>
But I need to change the text of tags to something more like this:
<field name="title">title</field>
<field name="text">text</field>
I am trying to write a little script in bash and use sed
command to change the text of the tags.
sed "s/<TEXT>/<field name"text">/g"
I use this command for every tag, but these files contain more than 20 different tags, so I think there must be a more efficient way to do this task.
Thank you for any help.
EDIT: Added sample input and output.
Input
<?xml version="1.0" encoding="UTF-8"?>
<DOC>
<DOCID>MF-20020103001</DOCID>
<DATE>01/03/02</DATE>
<TITLE>Example title</TITLE>
<TEXT>Very long text...</TEXT>
</DOC>
Output
<?xml version="1.0" encoding="UTF-8"?>
<doc>
<field name="docid">MF-20020103001</field>
<field name="date">01/03/02</field>
<field name="title">Example title</field>
<field name="text">Very long text...</field>
</doc>