Skip to content

Instantly share code, notes, and snippets.

@hostmaster
Last active December 19, 2015 08:49
Show Gist options
  • Save hostmaster/5928538 to your computer and use it in GitHub Desktop.
Save hostmaster/5928538 to your computer and use it in GitHub Desktop.
Correct malformed XML
#!/usr/bin/awk -f
BEGIN {
ss_start=0
ss_maybe=0
}
/<SS>/ {
ss_start=1
print $0
next;
}
/<\/SS>/ {
ss_start=0
ss_maybe=0
print $0
next;
}
/<\/TableCSS>/ {
if ( $0 ~ /<TableR>/) {
ss_maybe=0
} else {
ss_maybe=1
}
print $0
next;
}
/<TableR>/ {
ss_maybe=0
print $0
next;
}
/<\/TableR>/ {
if ( $0 ~ /<\/SS>/) {
ss_maybe=0
} else {
ss_maybe=1
}
print $0
next;
}
/^$/{
print $0
next;
}
/./ {
if (ss_start && ss_maybe){
ss_start=0
ss_maybe=0
print "</SS>"
}
print $0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment