jonobr
May 6th, 2009, 09:14 PM
Hello All,
My scripting ability is really laughable, and Im wondering if someone can help with this real easy stupid question..
Or point me to good bash or perl examples of this.
I have a whole bunch of xml files which I need to prepare for importing to another system.
Each xml files contents contain information which needs tags added to the start and finish. I will also have to have a search and replace.
Im doing this in vi at the moment, just adding the tags and then doing a
:%s/this/that/g
however now its getting unworkable as the number of files is increasing
SO heres an example of what I was hoping to get...
file1 contains
<rhyme>
<to>Mary</to>
<from>little-lamb</from>
<heading>Reminder</heading>
<body>My fleece is still white as snow</body>
</note>
I would like to Wrap the file with another tag eg <nusery> </nusery>
eg
<nursery>
<rhyme>
<to>Mary</to>
<from>little-lamb</from>
<heading>Reminder</heading>
<body>My fleece is still which as snow</body>
</rhyme>
</nursery>
After that I would want to remove certain things, eg, the "-" in "little-lamb" to make it littlelamb.
I would if possible like to make that more flexible,
in that , I want to look for
<from>little??????lamb</from>
I.e. anything that matches the front and the end and has a variable amount of info in the ????? and switch it to something else, e.g.
maybe littlelamb again.
<from>little dumb lamb</from>
<from>little pretty lamb</from>
<from>little supercalerfragalistic lamb</from>
all go to
<from>littlelamb</from>
Many thanks
My scripting ability is really laughable, and Im wondering if someone can help with this real easy stupid question..
Or point me to good bash or perl examples of this.
I have a whole bunch of xml files which I need to prepare for importing to another system.
Each xml files contents contain information which needs tags added to the start and finish. I will also have to have a search and replace.
Im doing this in vi at the moment, just adding the tags and then doing a
:%s/this/that/g
however now its getting unworkable as the number of files is increasing
SO heres an example of what I was hoping to get...
file1 contains
<rhyme>
<to>Mary</to>
<from>little-lamb</from>
<heading>Reminder</heading>
<body>My fleece is still white as snow</body>
</note>
I would like to Wrap the file with another tag eg <nusery> </nusery>
eg
<nursery>
<rhyme>
<to>Mary</to>
<from>little-lamb</from>
<heading>Reminder</heading>
<body>My fleece is still which as snow</body>
</rhyme>
</nursery>
After that I would want to remove certain things, eg, the "-" in "little-lamb" to make it littlelamb.
I would if possible like to make that more flexible,
in that , I want to look for
<from>little??????lamb</from>
I.e. anything that matches the front and the end and has a variable amount of info in the ????? and switch it to something else, e.g.
maybe littlelamb again.
<from>little dumb lamb</from>
<from>little pretty lamb</from>
<from>little supercalerfragalistic lamb</from>
all go to
<from>littlelamb</from>
Many thanks