Last active
December 15, 2015 11:59
-
-
Save ithayer/5257033 to your computer and use it in GitHub Desktop.
Simple python script to regex replace the contents of a file.
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
#!/usr/bin/env python | |
import os | |
import re | |
from optparse import OptionParser | |
parser = OptionParser() | |
(options, args) = parser.parse_args() | |
def eatFile(tmplfile): | |
print "Eating %s" % tmplfile | |
# Read file contents. | |
f = open(tmplfile) | |
z = f.read() | |
f.close(); | |
# Replace. | |
z = re.sub('^\s*(\d.\d)([A-z])', r"\1 \2", z, 0, re.MULTILINE) | |
# Rewrite file contents. | |
f = open(tmplfile, "w") | |
f.write(z); | |
f.close(); | |
for f in args: | |
eatFile(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment