Hi,
I'm having a xml file with multiple xml header. so i want to split the file into multiple files.
Sample.xml consists multiple headers so how can we split these multiple headers into multiple files in unix.
eg :
<?xml version="1.0" encoding="UTF-8"?>
<ml:individual xmlns:ml=http://www.ex xmlns >
<id>....
....
...
</ml:sample>
<?xml version="1.0" encoding="UTF-8"?>
<ml:individual xmlns:ml="ht"
<id>....
....
...
</ml:sample>
<?xml version="1.0" encoding="UTF-8"?>
<ml:individual xmlns:ml="htt" >
<id>....
....
...
</ml:sample>
Hello Narendra921631,
Welcome to forums, request you to please use code tags as per forum rules for commands/inputs/codes which you are using into your posts.
Now coming onto your requirement, please provide us following details.
i- It is always good to let us know your O.S details
ii- Please re-phrase your requirement again here, as there are some confusions here eg->
a- From which line to which line you need to split the files?
b- What should be file names which you need to get after splitting?
c- Is there any other requirement too here, along with these above?
Please let us know above points so that we could help you in same, hapy learning
and enjoy useful posting .
NOTE: Adding the RULES for forums link too here for your help.
Thanks,
R. Singh
Hi Ravinder,
Sure.
I want to split sample.xml
file into sample_1.xml
, sample_2.xml
Current platform redhat Linux machine
<?xml version="1.0" encoding="UTF-8"?>
<ml:individual xmlns:ml=http://www.ex >
<id>....
....
...
</ml:sample>
---- first file ( sample_1.xml
)
<?xml version="1.0" encoding="UTF-8"?>
<ml:individual xmlns:ml=http://www.ex >
<id>....
....
...
</ml:sample>
second file ( sample_2.xml
)
There are many ways to achieve what you want to do. Here is one way using awk:
awk 'BEGIN {NUM=0}; /xml version="1.0"/ {NUM++; filename=NUM".xml"}; {print >filename}' infile.xml
If you prefer a utility, have a look at csplit.