
Untitled
By: a guest on
May 2nd, 2012 | syntax:
None | size: 0.55 KB | hits: 16 | expires: Never
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
import subprocess
def do_sed(fullpath, old, new):
sed_script = "s/%s/%s/g" % (old, new)
command = ["sed", "-i", fullpath, "-e", sed_script]
subprocess.call(command)
if __name__ == '__main__':
argvs = sys.argv
argc = len(argvs)
if argc != 3:
sys.exit(1)
old = argvs[1]
new = argvs[2]
srcdir = "."
for root,dir,files in os.walk(srcdir):
for f in files:
fullpath = os.path.join(root,f)
do_sed(fullpath, old, new)