开发者

BASH SHELL SCRIPT to split a big xml file into multiple small files

I have a an XML file in below format

<?xml version="1.0" encoding="utf-8" ?>
<parent>
    <child>
        <code></code>
        <text></text>
    </child>
    <child>
        <code></code>
        <text>开发者_JS百科;</text>
    </child>
 </parent>

I need a BASH SHELL script to split this main xml file into multiple small XML files which should have contents from the <child> to </child> tag. File names could be parent file name plus a running serial number such as _1 for ex:20110721_1.xml etc.. Please help me with the script.


Not pure answer but you can tune this yourself:

csplit -ksf part. src.xml /\<child\>/ "{100}" 2>/dev/null

This command will split src.xml using regexp /\<child\>/ as a delimiter and produce 1..100 part.* files. You need to play with regexp though...


One solution is to write a XSL file and use xsltproc with the stylesheet and the xml file to generate the single files.

See How to split XML file into many XML files using XSLT for an example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜