Skip to content

Instantly share code, notes, and snippets.

@meeuw
Created December 4, 2014 09:42
Show Gist options
  • Save meeuw/2d8cb59499dbbcc5eec8 to your computer and use it in GitHub Desktop.
Save meeuw/2d8cb59499dbbcc5eec8 to your computer and use it in GitHub Desktop.
replace fields in xml file
import re
import fileinput
i = 0
output = {}
def repl(m):
global i
global output
i += 1
output[i] = m.group(2)
return m.group(1)+"%%replace{%i}" % i
for line in fileinput.input():
print re.sub(r"(label=\")([^\"]*)", repl, line),
for key, value in output.iteritems():
print str(key)+'\t'+value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment