Created
March 9, 2012 11:08
-
-
Save marekkalnik/2006101 to your computer and use it in GitHub Desktop.
AWK - split XML subnodes into separate files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This awk script splits an XML file and exports each node into separate file | |
# It doesn't work if the main node has an attribute | |
# It doesn't work if the main node contains a subnode with the same tagname, etc. | |
# Use at your own risk, think before using. | |
# Usage - replace "node" by your tag and run: $ awk -f split-xml.awk my.xml | |
/<node>/ { | |
rfile="node" count ".xml" | |
print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > rfile | |
print $0 > rfile | |
getline | |
while ($0 !~ "<\/node>" ) { | |
print > rfile | |
getline | |
} | |
print $0 > rfile | |
close(rfile) | |
count++ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment