Merge multiple XML files from command line

后端 未结 3 2035
粉色の甜心
粉色の甜心 2020-12-09 05:14

I have several xml files. They all have the same structure, but were splitted due to file size. So, let\'s say I have A.xml, B.xml, C.xml

3条回答
  •  孤城傲影
    2020-12-09 05:18

    Low-tech simple answer:

    echo '' > combined.xml
    grep -vh '\|> combined.xml
    echo '' >> combined.xml
    

    Limitations:

    • The opening and closing tags need to be on their own line.
    • The files need to all have the same outer tags.
    • The outer tags must not have attributes.
    • The files must not have inner tags that match the outer tags.
    • Any current contents of combined.xml will be wiped out instead of getting included.

    Each of these limitations can be worked around, but not all of them easily.

提交回复
热议问题