Skip to content
Advertisement

How to split a single XML file into multiple based on tags

I have an XML file that have tags. I want to split files like this.

JavaScript

Below is the code tried . But it is generating every single line into a new file

JavaScript

I want to split this file based on ORDER tags alone as mentioned below

JavaScript

Advertisement

Answer

With any awk in any shell on every UNIX box:

JavaScript

it’s obviously fragile as it’s just doing regexp matches against text, not parsing the XML, but it’ll work for the sample you posted and any similar text.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement